Skip to main content

pr_number_from_subject

Function pr_number_from_subject 

Source
pub fn pr_number_from_subject(subject: &str) -> Option<u32>
Expand description

The PR number a commit subject (the first line of its message) names, if it ends in the (#NNNN) GitHub’s squash-merge appends to the PR title — pure and root-independent, so xtask/src/main.rs’s pr_number_from_head (the only caller, which runs git log -1 --format=%s to get subject) stays a thin wrapper over this, and this half — the part with the interesting edge cases — is unit-testable without a git tree (#1001, caught by review as the one piece of new logic with no test coverage).

Known limitation, stated rather than guarded against: this matches on shape alone. Any subject ending (#NNNN) is read as the merging PR, including a hand-written commit that happens to end in an issue reference ("fix: handle empty spans (#1001)", where 1001 names an issue, not the PR that closes it) — correct on the squash-merge path this exists for, a silent false positive off it (a hand-run stamp --apply on an unmerged local commit, say). Not guarded against because the fix — only trust the parse when the run is known to be CI/merge-triggered — would also suppress the legitimate case of manually re-running stamp --apply against an already-merged commit to recover from a failed push (stamp.yml names this as the documented recovery path), which is a worse trade.