Skip to content

Commit 4b10786

Browse files
authored
Merge pull request #1147 from cloudbees-oss/AIENG-234
restore --link option to the build command
2 parents d629157 + cfc8bb3 commit 4b10786

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

smart_tests/commands/record/build.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import typer
77
from tabulate import tabulate
88

9+
from smart_tests.commands.record.session import KeyValue, LinkKind, parse_key_value
910
from smart_tests.utils.link import CIRCLECI_KEY, GITHUB_ACTIONS_KEY, JENKINS_URL_KEY, capture_link
1011
from smart_tests.utils.tracking import Tracking, TrackingClient
1112

@@ -71,6 +72,11 @@ def build(
7172
help="Used to overwrite the build time when importing historical data. "
7273
"Note: Format must be `YYYY-MM-DDThh:mm:ssTZD` or `YYYY-MM-DDThh:mm:ss` (local timezone applied)"
7374
)] = None,
75+
links: Annotated[List[KeyValue], typer.Option(
76+
"--link",
77+
help="Set external link of a title and url",
78+
parser=parse_key_value,
79+
)] = [],
7480
):
7581
app = ctx.obj
7682

@@ -283,9 +289,16 @@ def synthesize_workspaces() -> List[Workspace]:
283289

284290
# send all the data to server and obtain build_id, or none if the service is down, to recover
285291
def send(ws: List[Workspace]) -> str | None:
292+
# TODO(Konboi): port forward #1128
286293
# figure out all the CI links to capture
287294
def compute_links():
288295
_links = capture_link(os.environ)
296+
for k, v in links:
297+
_links.append({
298+
"title": k,
299+
"url": v,
300+
"kind": LinkKind.CUSTOM_LINK.name,
301+
})
289302
return _links
290303

291304
try:

smart_tests/commands/record/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def session(
4545
)] = False,
4646
links: Annotated[List[KeyValue], typer.Option(
4747
"--link",
48-
help="Set external link of atitle and url",
48+
help="Set external link of a title and url",
4949
parser=parse_key_value,
5050
)] = [],
5151
is_no_build: Annotated[bool, typer.Option(

tests/commands/record/test_build.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,33 @@ def test_repo_branch_map_requires_no_commit_collection(self):
384384
".=main")
385385
self.assert_exit_code(result, 1)
386386
self.assertIn("--no-commit-collection must be specified when --repo-branch-map is used", result.stdout)
387+
388+
@responses.activate
389+
@mock.patch.dict(os.environ, {"SMART_TESTS_TOKEN": CliTestCase.smart_tests_token})
390+
# to tests on GitHub Actions
391+
@mock.patch.dict(os.environ, {"GITHUB_ACTIONS": ""})
392+
@mock.patch.dict(os.environ, {"GITHUB_PULL_REQUEST_URL": ""})
393+
def test_with_link(self):
394+
result = self.cli(
395+
"record", "build", "--build", self.build_name,
396+
'--link', 'url=https://smart-tests.test',
397+
'--link', 'build:https://build.smart-tests.test',
398+
# set these options for easy to check payload
399+
"--no-commit-collection",
400+
"--branch", "main",
401+
"--commit", "app=abc12",
402+
)
403+
404+
self.assert_exit_code(result, 0)
405+
payload = json.loads(responses.calls[1].request.body.decode())
406+
self.assert_json_orderless_equal(
407+
{
408+
"buildNumber": "123",
409+
"lineage": "main",
410+
"commitHashes": [{"repositoryName": "app", "commitHash": "abc12", "branchName": ""}],
411+
"links": [
412+
{"title": "url", "url": "https://smart-tests.test", "kind": "CUSTOM_LINK"},
413+
{"title": "build", "url": "https://build.smart-tests.test", "kind": "CUSTOM_LINK"},
414+
],
415+
"timestamp": None
416+
}, payload)

0 commit comments

Comments
 (0)