diff --git a/bugbot/rules/uplift_beta.py b/bugbot/rules/uplift_beta.py index 0de67340e..c57704d7a 100644 --- a/bugbot/rules/uplift_beta.py +++ b/bugbot/rules/uplift_beta.py @@ -2,12 +2,17 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. +import re + from libmozdata import utils as lmdutils from libmozdata.bugzilla import Bugzilla from bugbot import utils from bugbot.bzcleaner import BzCleaner +LANDO_BASE_URL = "https://lando.moz.tools/" +PHAB_FILE_NAME_PAT = re.compile(r"phabricator-D([0-9]+)-url\.txt") + class UpliftBeta(BzCleaner): def __init__(self): @@ -36,6 +41,21 @@ def get_extra_for_needinfo_template(self): def columns(self): return ["id", "summary", "assignee"] + @staticmethod + def get_lando_url(attachments): + """Get Lando URL if there is exactly one non-obsolete Phabricator attachment.""" + rev_ids = [ + int(m.group(1)) + for attachment in attachments + if attachment["content_type"] == "text/x-phabricator-request" + and not attachment["is_obsolete"] + for m in [PHAB_FILE_NAME_PAT.match(attachment["file_name"])] + if m + ] + if len(rev_ids) == 1: + return f"{LANDO_BASE_URL}D{rev_ids[0]}" + return None + def handle_bug(self, bug, data): bugid = str(bug["id"]) @@ -55,6 +75,7 @@ def handle_bug(self, bug, data): "nickname": nickname, "summary": self.get_summary(bug), "regressions": bug["regressions"], + "lando_url": self.get_lando_url(bug.get("attachments", [])), } return bug @@ -102,6 +123,7 @@ def get_bz_params(self, date): "attachments.creation_time", "attachments.is_obsolete", "attachments.content_type", + "attachments.file_name", "cf_last_resolved", "assigned_to", "flags", @@ -143,7 +165,10 @@ def get_bugs(self, date="today", bug_ids=[]): for bugid, data in bugs.items(): if data["mail"] and data["nickname"]: - self.extra_ni[bugid] = {"regression": len(data["regressions"])} + self.extra_ni[bugid] = { + "regression": len(data["regressions"]), + "lando_url": data["lando_url"], + } self.add_auto_ni( bugid, {"mail": data["mail"], "nickname": data["nickname"]} ) diff --git a/templates/uplift_beta_needinfo.txt b/templates/uplift_beta_needinfo.txt index a5393b3e1..51992ffaf 100644 --- a/templates/uplift_beta_needinfo.txt +++ b/templates/uplift_beta_needinfo.txt @@ -1,7 +1,8 @@ The patch landed in nightly and beta is affected. :{{ nickname }}, is this bug important enough to require an uplift? - If yes, please nominate the patch for beta approval.{% if extra[bugid]["regression"] %} Also, don't forget to request an uplift for the patches in the {{ plural('regression', extra[bugid]["regression"]) }} caused by this fix.{% endif %} - - See https://wiki.mozilla.org/Release_Management/Requesting_an_Uplift for documentation on how to request an uplift. + - See https://wiki.mozilla.org/Release_Management/Requesting_an_Uplift for documentation on how to request an uplift.{% if extra[bugid]["lando_url"] %} + - The patch is available at {{ extra[bugid]["lando_url"] }}.{% endif %} - If no, please set `{{ extra["status_beta"] }}` to `wontfix`. {{ documentation }}