Skip to content

Commit

Permalink
Support multiple links in the tmt link command (#3309)
Browse files Browse the repository at this point in the history
In order to make the syntax consistent with the `tmt test create`
command and to allow providing multiple links in a single command
let's use a ``--link`` option instead of the first argument for
provide the `relation:target` pairs.
  • Loading branch information
psss authored Oct 23, 2024
1 parent d9f1430 commit e485608
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ later using the ``tmt link`` command:

.. code-block:: shell
tmt link verifies:https://issues.redhat.com/browse/YOUR-ISSUE tests/core/smoke
tmt link --link verifies:https://issues.redhat.com/browse/YOUR-ISSUE tests/core/smoke
In order to enable this feature, create a configuration file
``.config/tmt/link.fmf`` and define an ``issue-tracker`` section
Expand Down
4 changes: 4 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ to override the default locations.

__ https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux/image-mode

The ``tmt link`` command now supports providing multiple links by
using the ``--link`` option. See the :ref:`link-issues` section
for example usage.


tmt-1.37.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions tests/link/basic/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
summary: Check basic functionality of the tmt link command
description:
Make sure that `tmt test create` and `tmt link` add provided
target link to the test metadata.
35 changes: 35 additions & 0 deletions tests/link/basic/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create a tmp directory"
rlRun "pushd $tmp"
rlRun "tmt init"
rlPhaseEnd

rlPhaseStartTest "Create Test"
rlRun "tmt test create /test/created --template shell --link verifies:/feature/one"
rlRun -s "tmt test show /test/created"
rlAssertGrep "verifies /feature/one" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Existing Test"
rlRun "tmt test create /test/existing --template shell"
rlRun "tmt link /test/existing --link verifies:/feature/two"
rlRun "tmt link /test/existing --link verifies:/feature/three"
rlRun -s "tmt test show /test/existing"
rlAssertGrep "verifies /feature/two" $rlRun_LOG
rlAssertGrep "verifies /feature/three" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "No Link Provided"
rlRun -s "tmt link /test/existing" 2
rlAssertGrep "Provide at least one link" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove the tmp directory"
rlPhaseEnd
rlJournalEnd
23 changes: 16 additions & 7 deletions tmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2242,14 +2242,19 @@ def completion_fish(context: Context, install: bool, **kwargs: Any) -> None:

@main.command(name='link')
@pass_context
@click.argument('link', nargs=1, metavar='[RELATION:]TARGET')
@click.argument('names', nargs=-1, metavar='[TEST|PLAN|STORY]...')
@option(
'--link', 'links', metavar='[RELATION:]TARGET', multiple=True,
help="""
Issue to which tests, plans or stories should be linked.
Can be provided multiple times.
""")
@option(
'--separate', is_flag=True,
help="Create linking separately for multiple passed objects.")
def link(context: Context,
names: list[str],
link: str,
links: list[str],
separate: bool,
) -> None:
"""
Expand All @@ -2268,8 +2273,12 @@ def link(context: Context,
if not tmt_objects:
raise tmt.utils.GeneralError("No test, plan or story found for linking.")

tmt.utils.jira.link(
tmt_objects=tmt_objects,
links=tmt.base.Links(data=link),
separate=separate,
logger=context.obj.logger)
if not links:
raise tmt.utils.GeneralError("Provide at least one link using the '--link' option.")

for link in links:
tmt.utils.jira.link(
tmt_objects=tmt_objects,
links=tmt.base.Links(data=link),
separate=separate,
logger=context.obj.logger)

0 comments on commit e485608

Please sign in to comment.