Skip to content

Commit 4fc1537

Browse files
authored
Merge branch 'main' into Hani/cm-peacocks-gb
2 parents ec88206 + a7f5d28 commit 4fc1537

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

modules/testrail.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@ def create_new_plan_entry(
350350
payload["runs"] = runs
351351
return self.client.send_post(f"/add_plan_entry/{plan_id}", payload)
352352

353+
def update_plan(self, plan_id, **kwargs):
354+
"""Given a plan id, update the plan per kwargs"""
355+
if not kwargs:
356+
return False
357+
return self.client.send_post(f"/update_plan/{plan_id}", kwargs)
358+
359+
def update_plan_entry(self, plan_id, entry_id, **kwargs):
360+
"""Given a plan id and entry id, update the entry per kwargs"""
361+
if not kwargs:
362+
return False
363+
return self.client.send_post(f"/update_plan_entry/{plan_id}/{entry_id}", kwargs)
364+
353365
def matching_configs(self, testrail_project_id, config_group_id, config_name):
354366
"""Given a project id, a config group id, and a config name, return the matching config object"""
355367
configs = self.client.send_get(f"/get_configs/{testrail_project_id}")

modules/testrail_integration.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@
1919
PLAN_NAME_RE = re.compile(r"\[(\w+) (\d+)\]")
2020
CONFIG_GROUP_ID = 95
2121
TESTRAIL_FX_DESK_PRJ = 17
22+
TC_EXECUTION_TEMPLATE = "https://firefox-ci-tc.services.mozilla.com/tasks/%TASK_ID%/runs/%RUN_ID%/logs/public/logs/live.log"
23+
24+
25+
def get_execution_link() -> str:
26+
"""Using environment variables, get the link to the test execution"""
27+
link = ""
28+
if "TASKCLUSTER_PROXY_URL" in os.environ:
29+
link = TC_EXECUTION_TEMPLATE
30+
for item in ["RUN_ID", "TASK_ID"]:
31+
link = link.replace(f"%{item}%", os.environ.get(item))
32+
return link
33+
34+
35+
def replace_link_in_description(description, os_name) -> str:
36+
"""Add or replace a test execution link in the test run description"""
37+
logging.warning(f"Modifying plan description for %{os_name}%")
38+
if os_name not in description:
39+
# TODO: remove following conditional when links for GHA resolved
40+
if os_name == "Linux":
41+
return f"{description}\n[{os_name} execution link]({get_execution_link()})"
42+
else:
43+
link = get_execution_link()
44+
if link in description:
45+
return description
46+
lines = description.split("\n")
47+
for i, line in enumerate(lines):
48+
if os_name in line:
49+
lines[i] = (
50+
f"{description}\n[{os_name} execution link]({get_execution_link()})"
51+
)
52+
return description
2253

2354

2455
def get_plan_title(version_str: str, channel: str) -> str:
@@ -321,6 +352,12 @@ def organize_l10n_entries(
321352
if len(site_entries) != 1:
322353
logging.info("Suite entries are broken somehow")
323354

355+
# Add execution link to plan description
356+
357+
os_name = config.split(" ")[0]
358+
description = replace_link_in_description(expected_plan["description"], os_name)
359+
testrail_session.update_plan(plan_id, description=description)
360+
324361
# There should only be one entry per site per plan
325362
# Check that this entry has a run with the correct config
326363
# And if not, make that run

0 commit comments

Comments
 (0)