GeezerVison is showing github.com — fix(server): keep numeric merge subjects from matching the wrong PR w… · patroza/t3code@cbf5c78
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/sourceControl
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/sourceControl/sourceControlDefinitions.test.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,17 +61,23 @@ it.each([ | 61 | 61 | ["gh pr merge 19 --squash", [19]], | 62 | 62 | ['gh pr merge "19" --squash', [19]], | 63 | 63 | ['/bin/zsh -lc "gh pr merge 19"', [19]], | | 64 | + ['/bin/zsh -lc "gh pr merge 19" > "merge.log"', [19]], | | 65 | + [`/bin/zsh -lc 'gh pr merge 19' > 'merge.log'`, [19]], | 64 | 66 | ['gh pr merge 19 --squash --subject "Release 20"', [19]], | 65 | 67 | [`/bin/zsh -lc "gh pr merge 19 --subject 'Release 20'"`, [19]], | 66 | 68 | ["gh pr merge 19 --body 'see https://github.com/o/r/pull/20'", [19]], | 67 | 69 | ["gh pr merge 19 --body https://github.com/o/r/pull/20", [19]], | 68 | 70 | ["gh pr merge 19 # then 20", [19]], | 69 | 71 | ["gh pr merge --squash --match-head-commit 3b2f958 #19", [19]], | | 72 | + ["gh pr merge --squash --subject=2026 42", [42]], | | 73 | + ['gh pr merge --squash --subject="2026" 42', [42]], | | 74 | + ["gh pr merge --body=https://github.com/o/r/pull/20 19", [19]], | 70 | 75 | ["gh pr close https://github.com/o/r/pull/19 && gh pr merge 20", [19, 20]], | 71 | 76 | ["glab mr merge https://gitlab.com/o/r/-/merge_requests/7", [7]], | 72 | 77 | ["sleep 30; cafe pr merge 26271", [26271]], | 73 | 78 | ["az repos pr update --id 19 --status completed", [19]], | 74 | 79 | ["az repos pr update --id=19 --status=abandoned", [19]], | | 80 | + ['az repos pr update --id="19" --title "20" --status completed', [19]], | 75 | 81 | ["gh pr merge --squash", "any"], | 76 | 82 | ["gh stack merge", "any"], | 77 | 83 | ["gh pr merge 19 && gh pr merge --auto", "any"], | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/sourceControl/sourceControlDefinitions.ts +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,10 +32,15 @@ export const isChangeRequestCloseCommand = (command: string) => | 32 | 32 | ); | 33 | 33 |
| 34 | 34 | // A quoted or bare shell word. An unclosed quote, as Codex's `/bin/zsh -lc "gh pr merge 19"` | 35 | | -// leaves after the match, runs to the end. | 36 | | -const SHELL_WORD = /"((?:\\[\s\S]|[^"\\])*)"?|'([^']*)'?|((?:\\[\s\S]|[^\s"'\\])+)/gu; | 37 | | -// A whole word that names one, so a number inside `--subject "Release 20"` does not. | 38 | | -const NAMED_CHANGE_REQUEST = /^(?:--?[\w-]+=)?#?(\d+)$|^\S*\/(?:pulls?|merge_requests)\/(\d+)\/?$/u; | | 35 | +// leaves after the match, runs to the end. A closed one right after `=` stays in that word and is | | 36 | +// unquoted before matching, so `--id="19"` names 19 and `--subject="20"` names none, while the | | 37 | +// wrapper's closing quote in `-lc "gh pr merge 19" > "log"` still ends the word `19`. | | 38 | +const SHELL_WORD = | | 39 | + /"((?:\\[\s\S]|[^"\\])*)"?|'([^']*)'?|((?:\\[\s\S]|[^\s"'\\])+(?:(?<==)(?:"(?:\\[\s\S]|[^"\\])*"|'[^']*'))?)/gu; | | 40 | +// A whole word that names one, so a number inside `--subject "Release 20"` does not. Of the | | 41 | +// hosts' close commands only Azure's selects one with a flag, so `--subject=2026` and | | 42 | +// `--body=<pull request URL>` are option text. | | 43 | +const NAMED_CHANGE_REQUEST = /^(?:--id=)?#?(\d+)$|^(?!-)\S*\/(?:pulls?|merge_requests)\/(\d+)\/?$/u; | 39 | 44 |
| 40 | 45 | /** | 41 | 46 | * The change request numbers a merge or close command names, or "any" when one names none, as a | @@ -53,7 +58,8 @@ export function changeRequestsClosedBy(command: string): ReadonlySet<number> | " | 53 | 58 | for (const [, double, single, bare] of args.matchAll(SHELL_WORD)) { | 54 | 59 | // A comment ends the command. | 55 | 60 | if (bare !== undefined && /^#(?!\d+$)/u.test(bare)) break; | 56 | | - const [, number, url] = NAMED_CHANGE_REQUEST.exec(double ?? single ?? bare ?? "") ?? []; | | 61 | + const word = double ?? single ?? bare?.replace(/\\([\s\S])|["']/gu, "$1") ?? ""; | | 62 | + const [, number, url] = NAMED_CHANGE_REQUEST.exec(word) ?? []; | 57 | 63 | target = number ?? url; | 58 | 64 | if (target !== undefined) break; | 59 | 65 | } | |
|