Skip to content

Commit 698b2dd

Browse files
fix(server): each host's created URLs are counted against its own create commands
AI-assisted; verified with the tests and tools listed above.
1 parent 5ba2c5d commit 698b2dd

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,25 @@ describe("PullRequestSyncReactor", () => {
17841784
output: `[\n${AZURE_PULL_REQUEST_CREATED}\n]\nhttps://github.com/owner/repository/pull/124\n`,
17851785
linked: [124],
17861786
},
1787+
{
1788+
name: "an existing GitHub pull request printed beside GitHub and Azure DevOps creates",
1789+
input:
1790+
"gh pr view --json url --jq .url && az repos pr create --title test --output none && gh pr create --fill",
1791+
output:
1792+
"https://github.com/owner/repository/pull/120\nhttps://github.com/owner/repository/pull/124\n",
1793+
linked: [],
1794+
},
1795+
{
1796+
name: "a GitHub pull request beside an Azure DevOps create that also printed an existing one",
1797+
input:
1798+
'az repos pr show --id "$PR_ID" && az repos pr create --title test && gh pr create --fill',
1799+
output: [
1800+
AZURE_PULL_REQUEST_CREATED,
1801+
AZURE_PULL_REQUEST_CREATED.replaceAll("42", "43"),
1802+
"https://github.com/owner/repository/pull/124",
1803+
].join("\n"),
1804+
linked: [124],
1805+
},
17871806
{
17881807
name: "an Azure DevOps pull request after a push",
17891808
input:

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ type CommandExecution = Extract<OrchestrationV2TurnItem, { readonly type: "comma
139139
/**
140140
* The change requests a shell command opened: the URLs a host's create command printed, on lines
141141
* of their own unless the host reads its output another way. One the command also names, as
142-
* `gh pr view 12` does, existed before it ran. More URLs than create commands means something
143-
* else printed some, such as `gh pr list`, so none are taken.
142+
* `gh pr view 12` does, existed before it ran. More of a host's URLs than its create commands
143+
* means something else printed some, such as `gh pr list`, so none of that host's are taken.
144144
*/
145145
export function changeRequestsCreatedBy(input: string, output: string) {
146146
if (!CREATE_COMMANDS.some(({ command }) => command.test(input))) return [];
@@ -156,10 +156,11 @@ export function changeRequestsCreatedBy(input: string, output: string) {
156156
const otherScript = shellSegments(script)
157157
.filter((segment) => createCommandCount(shellCode(segment)) === 0)
158158
.join("\n");
159-
const created = new Map<string, ThreadPullRequestKey & { readonly url: string }>();
159+
const created: Array<ThreadPullRequestKey & { readonly url: string }> = [];
160160
for (const { definition, run } of CREATE_COMMANDS) {
161-
if (code.match(run) === null || definition.changeRequestListCommand?.test(otherCommands))
162-
continue;
161+
const hostCreates = [...code.matchAll(run)].length;
162+
if (hostCreates === 0 || definition.changeRequestListCommand?.test(otherCommands)) continue;
163+
const hostCreated = new Map<string, ThreadPullRequestKey & { readonly url: string }>();
163164
const printed =
164165
definition.changeRequestCreateOutputUrls?.(output) ??
165166
Array.from(output.matchAll(URL_LINE), ([, url = ""]) => url);
@@ -172,10 +173,11 @@ export function changeRequestsCreatedBy(input: string, output: string) {
172173
// Quoted text in the other commands counts, as in `printf '.../pull/12'`.
173174
if (named.test(otherScript)) continue;
174175
const key = normalizeThreadPullRequestKey(link);
175-
created.set(threadPullRequestKeyOf(key), { ...key, url });
176+
hostCreated.set(threadPullRequestKeyOf(key), { ...key, url });
176177
}
178+
if (hostCreated.size <= hostCreates) created.push(...hostCreated.values());
177179
}
178-
return created.size > creates ? [] : [...created.values()];
180+
return created;
179181
}
180182

181183
const isPullRequestProviderError = Schema.is(PullRequestProviderError);

0 commit comments

Comments
 (0)