Commit cd3efc5
authored
fix(buds): stop unrelated PRs leaking onto PROD / UAT tabs (#193)
* fix(buds): stop unrelated PRs leaking onto PROD / UAT tabs
The release-stage tabs (PROD, UAT) were showing every open PR raised to
the configured branch on any impacted repo — including PRs linked to a
different BUD entirely. Root cause was the OR-of-equalities predicate
in ``list_open_for_bud_with_repo`` which let ``repo_id IN impacted``
bypass the BUD link.
Two coordinated fixes:
1. **Broaden the BUD-NNN resolver.** ``extract_bud_number`` now scans
PR titles in addition to head branches, with a negative-lookbehind
regex that rejects mid-word and run-on matches (``auth-bud-7``,
``abcbud-5``) while accepting the punctuation real titles use
(``Closes #BUD-4``, ``fix,BUD-3``, ``revert: BUD-21 cleanup``). The
webhook handler now also processes ``pull_request.edited`` events
gated on ``changes.title``, so retitling an orphan PR to
``[BUD-008] X`` relinks it on the next webhook. Old + new BUD both
get audit timeline events. The duplicate regex in ``mcp.handlers_hooks``
is removed in favour of the single seam.
2. **Tighten the stage-tab query.** ``list_open_for_bud_with_repo`` now
uses ``bud_id == X OR (bud_id IS NULL AND repo_id IN impacted)``.
The IS-NULL arm preserves aggregate release PRs (``develop → main``)
that legitimately carry no single owning BUD; PRs linked to a
different BUD on the same impacted repo no longer leak.
Adds ``scripts.backfill_pr_bud_links`` to re-link existing orphan PRs
using the broadened resolver. Defaults to open PRs only; an explicit
``--include-merged`` opts in to merged-PR backfill behind a CONFIRM
prompt because the next release-detection walk can fire new
``merged_to_{stage}`` timeline events and auto-close BUDs that were
previously orphaned in the release chain.
Tests: 5 parametrized-accept and 8 parametrized-reject cases pin the
matcher; predicate-shape tests pin the three-way SQL form.
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>
* fix(buds): release-stage tabs filter open PRs by BUD-number reference
The previous over-match fix preserved aggregate release PRs by keeping
``bud_id IS NULL`` rows on impacted repos visible — but that pulled in
unrelated PRs to ``main`` / ``release/*`` that simply happened to share
a repo with the BUD (e.g. an ATOA-9396 PR appearing on BUD-004's PROD
tab even though it has no BUD reference at all).
Real semantics: a PR belongs on a BUD's release-stage tab only when
its head ref or title carries that BUD's number. Multi-BUD release
branches like ``release/bud-001-bud-004-bud-007`` should surface on
EACH referenced BUD's tab, not on every impacted-repo BUD.
Adds two helpers in ``pr_auto_transition``:
- ``extract_all_bud_numbers(text)`` returns every BUD number found.
- ``pr_references_bud(num, head, title)`` is the call site.
Loosens the matcher's left lookbehind so digit-then-hyphen prefixes
are allowed (``-bud-`` after a digit is the multi-BUD chain pattern),
while keeping letter-then-hyphen prefixes rejected (``auth-bud-7``
mid-word case is still rejected).
The release-stage filter in ``bud_prs.py`` now applies the content
guard to any PR that isn't directly linked to this BUD — directly
linked PRs short-circuit so a user-edited link wins over text matching.
Tests pin the multi-BUD branch parser and the user's exact reported
case (``release/bud-001-bud-004`` matches BUD-1 and BUD-4 but not
BUD-7; unrelated ``ATOA-9396`` PR no longer leaks onto BUD-4's tab).
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>
* fix(buds): sync base_branch / head_branch on pull_request.edited
The edited webhook handler only synced ``title`` — base-branch and
head-branch changes from GitHub were silently dropped. When a PR was
retargeted from ``main`` to ``develop`` (the BUD-004 / PR-1997 case),
the local row kept ``base_branch = main`` and the release-stage filter
kept matching the PR onto the PROD tab because ``branch_matches``
runs against the stale value.
Two coordinated changes:
* Dispatcher widens the ``edited`` action gate. We now act when the
payload's ``changes`` carries ``title`` OR ``base`` — the two fields
that affect either the BUD link or the release-stage filter. Body /
label edits stay silent.
* Handler also assigns ``pr.base_branch`` and ``pr.head_branch`` from
the latest pr_data on every invocation. Cheap, and prevents the same
drift on future force-pushes or base-branch edits.
Does NOT retroactively fix already-stale rows: an operator-triggered
sync script or a webhook replay is needed for those. The unit test
also pins that the loose space-form title ``Bud 004/processing loader``
does NOT satisfy ``pr_references_bud`` on its own; the head branch
``bud-004/...`` is the reliable link source.
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>
* fix(buds): tighten BUD-NNN matcher + guard relink to title-only edits
Code review of the post-merge fixes flagged two real regressions and
one auto-transition risk:
* The relaxed regex ``(?<![A-Za-z])(?<![A-Za-z]-)`` accepted
``1bud-3``, ``sha7bud-5``, ``v2bud-5``, and ``auth1-bud-7`` —
digit-glued mid-word and prefix-with-trailing-digit shapes that
are not real BUD references. Revert to the strict
``(?<![A-Za-z0-9-])`` prefix that uniformly rejects letters,
digits, and hyphens on the left. Multi-BUD release branches are
now handled by a SEPARATE chain matcher: ``extract_all_bud_numbers``
finds each strict ``bud-NNN`` match and then walks forward through
any ``-bud-NNN-bud-NNN`` tail. Six new parametrize-reject cases
pin the digit-glued and trailing-digit-prefix rejections.
* ``_handle_pr_edited`` previously called ``resolve_bud_from_pr`` on
every invocation. Now that the dispatcher also fires on base edits,
unconditional re-resolution risked unlinking a PR whose title
carried a once-accepted-now-rejected reference (the regex tightening
is exactly that kind of contract change). Gate the relink to actual
title changes; base / head edits still sync ``pr.base_branch`` and
``pr.head_branch`` but do not touch ``pr.bud_id``.
Auto-transition audit confirmed clean:
* ``check_all_repos_have_prs`` / ``check_all_prs_merged`` key off
``pr.bud_id``, not the text content — the matcher tightening only
affects NEW PR-open / title-edit links, not existing rows.
* The development → code_review threshold is unaffected by base
edits because the gate above blocks the only path that could have
unlinked an existing link on a base-only edit.
Full backend suite green: 1887 passed.
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>
---------
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>1 parent 49aec62 commit cd3efc5
8 files changed
Lines changed: 812 additions & 40 deletions
File tree
- backend
- app
- api/v1
- mcp
- repositories
- services
- scripts
- tests
- repositories
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
247 | 261 | | |
248 | 262 | | |
249 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
297 | 299 | | |
298 | 300 | | |
299 | 301 | | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
180 | 189 | | |
181 | 190 | | |
182 | 191 | | |
183 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
184 | 195 | | |
185 | 196 | | |
186 | 197 | | |
187 | 198 | | |
188 | | - | |
189 | 199 | | |
190 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
191 | 209 | | |
192 | 210 | | |
193 | 211 | | |
| |||
198 | 216 | | |
199 | 217 | | |
200 | 218 | | |
201 | | - | |
| 219 | + | |
202 | 220 | | |
203 | 221 | | |
204 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
56 | | - | |
57 | 54 | | |
58 | 55 | | |
59 | 56 | | |
| |||
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| |||
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
107 | | - | |
| 114 | + | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
| |||
408 | 415 | | |
409 | 416 | | |
410 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
411 | 525 | | |
412 | 526 | | |
413 | 527 | | |
| |||
0 commit comments