Skip to content

Commit 94f1939

Browse files
committed
landing_checks: block commits with REPO- flag mismatch (bug 2032267) r=sheehan
We use the Lando `repo.name`, e.g., firefox-autoland. This won't match the name that the VCT hook uses, e.g., autoland. This means we will need to disable the equivalent HgMO check after this has landed. * landing_checks: add support for `repo_name` to `LandingChecks` * landing_checks: block commits with `REPO-` flag mismatch (bug 2032267) * tests: add `ids` to `test_check_commit_message_invalid_message` * tests: DRY `HG_PATCH_AUTHOR_COMMIT_MESSAGE_TEMPLATE` in `landing_checks` * tests: port `repolocked` tests from v-c-t Pull request: #1091
1 parent d352091 commit 94f1939

5 files changed

Lines changed: 231 additions & 60 deletions

File tree

src/lando/api/legacy/commit_message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# "bug" syntax like "bug X" or "b=".
1313
BUG_CONSERVATIVE_RE = re.compile(r"""(\b(?:bug|b=)\b(?:\s*)(\d+)(?=\b))""", re.I | re.X)
1414

15+
# Catch REPO-<reponame> locking flags.
16+
REPO_FLAG_RE = re.compile(r"[\s.;]REPO-(?P<repo>[-/a-zA-Z0-9]+)(?=[\s.;]|$)")
17+
18+
1519
SPECIFIER = r"\b(?:r|a|sr|rs|ui-r)[=?]"
1620
SPECIFIER_RE = re.compile(SPECIFIER)
1721

src/lando/api/legacy/workers/automation_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def run_job(self, job: AutomationJob) -> bool:
102102

103103
if not self.skip_checks(job, new_commits) and repo.hooks_enabled:
104104
patch_helpers = repo.scm.get_patch_helpers_for_commits(new_commits)
105-
landing_checks = LandingChecks(job.requester_email)
105+
landing_checks = LandingChecks(job.requester_email, repo.name)
106106
try:
107107
check_errors = landing_checks.run(repo.hooks, patch_helpers)
108108
except Exception as exc:

src/lando/api/legacy/workers/landing_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def apply_patch(revision: Revision):
339339

340340
if repo.hooks_enabled:
341341
patch_helpers = repo.scm.get_patch_helpers_for_commits(new_commits)
342-
landing_checks = LandingChecks(job.requester_email)
342+
landing_checks = LandingChecks(job.requester_email, repo.name)
343343
try:
344344
check_errors = landing_checks.run(repo.hooks, patch_helpers)
345345
except Exception as exc:

src/lando/utils/landing_checks.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from lando.api.legacy.commit_message import (
1515
ACCEPTABLE_MESSAGE_FORMAT_RES,
1616
INVALID_REVIEW_FLAG_RE,
17+
REPO_FLAG_RE,
1718
is_backout,
1819
parse_backouts,
1920
parse_bugs,
@@ -446,6 +447,7 @@ class PatchCollectionCheck(Check, ABC):
446447
"""
447448

448449
push_user_email: str | None = None
450+
repo_name: str | None = None
449451

450452
@abstractmethod
451453
def next_diff(self, patch_helper: PatchHelper):
@@ -510,6 +512,19 @@ def next_diff(self, patch_helper: PatchHelper):
510512
)
511513
return
512514

515+
if match := REPO_FLAG_RE.findall(firstline):
516+
for repo in match:
517+
if "/" in repo:
518+
self.commit_message_issues.append(
519+
f"Push contains commits intended to be locked to {repo} but the repo name is badly formatted. '/' is not allowed: {commit_message}"
520+
)
521+
return
522+
if self.repo_name not in match:
523+
self.commit_message_issues.append(
524+
f"Commit locked to a repo other than {self.repo_name}: {commit_message}"
525+
)
526+
return
527+
513528
if INVALID_REVIEW_FLAG_RE.search(firstline):
514529
self.commit_message_issues.append(
515530
f"Revision contains 'r?' in the commit message. Please use 'r=' instead: {commit_message}"
@@ -672,6 +687,7 @@ class PatchCollectionAssessor:
672687

673688
patch_helpers: Iterable[PatchHelper]
674689
push_user_email: str | None = None
690+
repo_name: str | None = None
675691

676692
def run_patch_collection_checks(
677693
self,
@@ -686,7 +702,10 @@ def run_patch_collection_checks(
686702
"""
687703
issues = []
688704

689-
checks = [check(self.push_user_email) for check in patch_collection_checks]
705+
checks = [
706+
check(self.push_user_email, self.repo_name)
707+
for check in patch_collection_checks
708+
]
690709

691710
for patch_helper in self.patch_helpers:
692711
# Pass the patch information into the push-wide check.
@@ -724,9 +743,11 @@ class LandingChecks:
724743
"""Utility class to run landing checks (a.k.a. hooks) on a list of commits."""
725744

726745
requester_email: str
746+
repo_name: str
727747

728-
def __init__(self, requester_email: str):
748+
def __init__(self, requester_email: str, repo_name: str):
729749
self.requester_email = requester_email
750+
self.repo_name = repo_name
730751

731752
def run(
732753
self,
@@ -754,7 +775,9 @@ def run(
754775
stack_checks = [chk for chk in ALL_STACK_CHECKS if chk.name() in hook_names]
755776

756777
assessor = PatchCollectionAssessor(
757-
patches, push_user_email=self.requester_email
778+
patches,
779+
push_user_email=self.requester_email,
780+
repo_name=self.repo_name,
758781
)
759782
return assessor.run_patch_collection_checks(
760783
patch_collection_checks=stack_checks, patch_checks=commit_checks

0 commit comments

Comments
 (0)