Commit eb07a83
nextchanges: Attribute stacked-PR fragments to the PR that added them (#6546)
## Changes
Fix `tools/validate_nextchanges.py` to attribute each `.nextchanges/`
fragment
to the PR that actually introduced it, rather than always the current
PR.
The changelog-preview check requires every fragment's trailing PR link
to name
the current PR. It infers the expected PR from the squash-merge commit
subject
(`(#N)`), falling back to the current PR for fragments not yet on main.
That
fallback is wrong for a **gh-stacked PR**: the fragments inherited from
earlier
PRs in the stack are added by ordinary branch commits (no `(#N)`
subject), so
they were attributed to the top PR — and CI failed even though each
fragment
already carried the correct link to the earlier PR.
Concretely, [#6544](#6544)
(stacked on the
SDK bump [#6448](#6448)) failed
with:
```
.nextchanges/dependency-updates/bump-sdk-0.177.0.md: trailing PR link #6448 must include the PR that added this fragment (#6544)
```
## Fix
A fragment that already exists on the PR's **base branch** was
introduced by an
earlier PR (upstream, or lower in the stack), so it is no longer
attributed to
the current PR — it keeps its own link and is only required to be
well-formed.
Fragments the PR genuinely adds still must name the current PR, as
before.
- `infer_expected_pr` returns `None` (no specific PR imposed) when the
fragment
is present on the base branch (`fragment_on_base`), instead of falling
back to
the current PR.
- The base branch is `BASE_REF` (`github.event.pull_request.base.ref`)
in CI, or
a best-effort `gh` lookup locally (`detect_base_ref` /
`current_branch_base`,
mirroring the existing PR detection).
- The changelog-preview workflow now passes `BASE_REF` to the validate
step.
Behavior is unchanged for non-stacked PRs, pushes to main (fragments
keep their
`(#N)` attribution), and the merge queue's shallow checkout (PR-link
checks are
already skipped there).
## Tests
- Existing doctests pass (`python -m doctest
tools/validate_nextchanges.py`).
- Reproduced a two-branch stack in a scratch repo: the old code fails on
the
inherited fragment with the same error as #6544; with `BASE_REF` set to
the
base branch it passes. The genuinely-new fragment still requires the top
PR's
link.
This pull request and its description were written by Isaac.
---------
Co-authored-by: Isaac <no-reply@databricks.com>1 parent 8fb31b8 commit eb07a83
2 files changed
Lines changed: 85 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
177 | 180 | | |
178 | 181 | | |
179 | 182 | | |
| |||
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| 196 | + | |
| 197 | + | |
193 | 198 | | |
194 | 199 | | |
195 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
196 | 228 | | |
197 | 229 | | |
198 | 230 | | |
| |||
225 | 257 | | |
226 | 258 | | |
227 | 259 | | |
228 | | - | |
| 260 | + | |
229 | 261 | | |
230 | 262 | | |
231 | 263 | | |
232 | 264 | | |
233 | 265 | | |
234 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
235 | 269 | | |
236 | 270 | | |
237 | 271 | | |
| |||
268 | 302 | | |
269 | 303 | | |
270 | 304 | | |
271 | | - | |
| 305 | + | |
272 | 306 | | |
273 | 307 | | |
274 | 308 | | |
| |||
332 | 366 | | |
333 | 367 | | |
334 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
335 | 406 | | |
336 | 407 | | |
337 | 408 | | |
| |||
403 | 474 | | |
404 | 475 | | |
405 | 476 | | |
| 477 | + | |
406 | 478 | | |
407 | 479 | | |
| 480 | + | |
408 | 481 | | |
409 | 482 | | |
410 | | - | |
| 483 | + | |
411 | 484 | | |
412 | 485 | | |
413 | 486 | | |
| |||
0 commit comments