Skip to content

Commit 592995c

Browse files
dcramercodex
andcommitted
fix(flue): Fallback for older gh duplicate closure
Check whether the installed gh CLI supports --duplicate-of before linking duplicate closures. Fall back to --reason duplicate on older runners so duplicate triage can still close the issue instead of degrading to human review. Co-Authored-By: GPT-5 Codex <noreply@openai.com>
1 parent 489152c commit 592995c

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

.flue/agents/issue-triage.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,27 @@ async function runGhCommand(
354354
}
355355
}
356356

357+
export function hasDuplicateOfFlag(helpText: string) {
358+
return helpText.includes("--duplicate-of");
359+
}
360+
361+
let duplicateOfFlagSupported: boolean | undefined;
362+
363+
async function supportsDuplicateOfFlag(session: FlueSession) {
364+
if (duplicateOfFlagSupported !== undefined) {
365+
return duplicateOfFlagSupported;
366+
}
367+
368+
const result = await session.shell("gh issue close --help", {
369+
commands: [gh],
370+
timeout: 60_000,
371+
});
372+
duplicateOfFlagSupported =
373+
result.exitCode === 0 && hasDuplicateOfFlag(`${result.stdout}\n${result.stderr}`);
374+
375+
return duplicateOfFlagSupported;
376+
}
377+
357378
async function withGhBodyFile<T>(
358379
prefix: string,
359380
body: string,
@@ -524,9 +545,13 @@ async function closeDuplicate(
524545
"Closing issue as not planned",
525546
);
526547
} else {
548+
const canLinkDuplicate = await supportsDuplicateOfFlag(session);
549+
const duplicateOfArg = canLinkDuplicate
550+
? ` --duplicate-of ${duplicate.number}`
551+
: "";
527552
await runGhCommand(
528553
session,
529-
`gh issue close ${context.issueNumber}${repoArg(context.repository)} --reason duplicate --duplicate-of ${duplicate.number}`,
554+
`gh issue close ${context.issueNumber}${repoArg(context.repository)} --reason duplicate${duplicateOfArg}`,
530555
"Closing duplicate issue",
531556
);
532557
}

.flue/tests/issue-triage.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
22

33
import {
44
buildDuplicateClosureComment,
5+
hasDuplicateOfFlag,
56
hasIssueTriageBotIntro,
67
wasClosedAsNotPlanned,
78
withIssueTriageBotIntro,
@@ -74,4 +75,11 @@ describe("duplicate closure", () => {
7475
"already closed as not planned",
7576
);
7677
});
78+
79+
it("detects whether gh can link duplicate closures", () => {
80+
expect(hasDuplicateOfFlag(" --duplicate-of int Issue number")).toBe(
81+
true,
82+
);
83+
expect(hasDuplicateOfFlag(" --reason string Reason")).toBe(false);
84+
});
7785
});

0 commit comments

Comments
 (0)