auto-backport: enforce a Fixes reference when a backport label is added#199
Conversation
|
Why are you using Your code will fail in many cases that the extract_jira_keys function handles today. |
has_fixes_reference() only recognised the literal 'Fixes' keyword with an uppercase Jira key, so PRs using Closes/Resolves/Fix/Fixed, an all-caps keyword, or a lowercase project key were treated as missing a reference and had their backport labels wrongly stripped (review on PR scylladb#199). Extract the canonical closing-keyword regex into scripts/closing_keywords.py and consume it from both scripts/jira_sync_modules.py (extract_jira_keys) and the backport enforcement, so the two agree on what counts as an issue reference. GitHub issue/PR references stay supported. The shared module is pure-stdlib and 3.9-compatible so the backport unit tests still run on 3.9.
d014a07 to
34a7e9e
Compare
|
Squashed into a single commit and addressed the review feedback. What this PR does (RELENG-175)When a Change since your review (@dani-tweig)You were right that This fixes the false negatives you flagged. These are now all recognized:
GitHub issue/PR references ( A couple of notes:
TestsAdded @dani-tweig could you take another look? Thanks! |
|
Using an extended regex is good, but Again, why not use the existing function? |
d76578e to
51a1b02
Compare
v3 — simplified, and using
|
| PR body | result |
|---|---|
Fixes: AAA-123 (unknown project) |
❌ rejected |
Fixes: SCYLLADB-9898758758 (real project, bad number) |
❌ rejected |
Fixes: SCYLLADB-123 (exists) |
✅ allowed |
If existence can't be confirmed (Jira unreachable), it fails open so a valid PR isn't blocked by a transient outage.
How simple it ended up
The feature is now one commit, +415 (most of it tests), with no new workflow and no new entrypoint. The labeled event already flows through main_pr_events_jira_sync.yml → jira_sync_logic.py → manage_labeled_gh_event, which already early-exited on backport/ labels — that early-exit is the only hook point needed. The enforcement lives next to extract_jira_keys/_gh_api in jira_sync_modules.py, plus a 14-line branch in the orchestrator.
373 passed (18 new enforcement tests). Could you take another look? Thanks! 🙏
…is added Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
f842ac3 to
4104899
Compare
RELENG-175
Force a PR to link a valid, existing issue as early as a backport label is added, instead of only after merge — so the work is visible sooner and gets release-note coverage.
Behaviour
When a
backport/<release>(orbackport/manager-X.Y) label is added to a PR whose body does not link a valid, existing issue, the automation:backport/noneis exempt. The comment is posted only once even when several backport labels are added together.What "valid" means
Reuses the existing
extract_jira_keys()for closing-keyword detection (Fixes:/Closes:/Resolves:...) and project-key validation (hard-coded set first, live Jira project list for unknown prefixes), then additionally confirms the referenced issue exists (JiraGET, 404 ⇒ reject). So:Fixes: AAA-123(unknown project) → rejectedFixes: SCYLLADB-9898758758(real project, non-existent number) → rejectedFixes: SCYLLADB-123(exists) → allowedIf existence can't be confirmed (Jira unreachable), it fails open so a valid PR isn't penalised for a transient outage. A GitHub-only ref (
Fixes: #123) does not satisfy it — the link must be to a Jira issue.Implementation
Hooks into the existing labeled-event path (
jira_sync_logic.py, run bymain_pr_events_jira_sync.yml), wherebackport/labels were already excluded from Jira sync — no new workflow or entrypoint.scripts/jira_sync_modules.py—enforce_backport_fixes_reference()+ helpers (_pr_body_links_existing_issue,_jira_issue_exists,_build_pr_mentions, …), reusing_gh_api+extract_jira_keys.scripts/jira_sync_logic.py— enforce onbackport/<release>inmanage_labeled_gh_event(+14 lines)..github/tests/test_enforce_backport_fixes.py— 18 tests.Testing
373 passed(full suite, includes the 18 new tests).Fixes: RELENG-175