feat(FN-4378): complete Step 2 — add github issue delete capability

Fusion-Task-Id: FN-4378
Fusion-Task-Lineage: d3867ba8-f852-41e3-9db0-584c0ffc23b1
This commit is contained in:
Fusion
2026-05-13 13:28:54 -07:00
committed by gsxdsm
parent 9bd1834e94
commit b742e1ac7c
2 changed files with 54 additions and 0 deletions

View File

@@ -600,6 +600,41 @@ describe("GitHubClient", () => {
});
});
describe("deleteIssue", () => {
it("deletes an issue via gh CLI", async () => {
mockRunGh.mockReturnValue("deleted");
const ghClient = new GitHubClient({ forceMode: "gh-cli" });
await ghClient.deleteIssue("owner", "repo", 123);
expect(mockRunGh).toHaveBeenCalledWith([
"issue",
"delete",
"123",
"--repo",
"owner/repo",
"--yes",
]);
});
it("surfaces gh CLI failures", async () => {
mockRunGh.mockImplementation(() => {
throw new Error("permission denied");
});
const ghClient = new GitHubClient({ forceMode: "gh-cli" });
await expect(ghClient.deleteIssue("owner", "repo", 124)).rejects.toThrow("permission denied");
});
it("rejects deletion in token-only mode with explanatory error", async () => {
const tokenClient = new GitHubClient({ token: "ghp_token", forceMode: "token" });
await expect(tokenClient.deleteIssue("owner", "repo", 125)).rejects.toThrow(
"Deleting GitHub issues requires gh CLI authentication. Token-only mode does not support issue deletion.",
);
});
});
describe("getBatchIssueStatus", () => {
it("uses the REST issues list endpoint for recent requested issues", async () => {
mockRunGhJsonAsync.mockResolvedValue([

View File

@@ -1506,6 +1506,25 @@ export class GitHubClient {
}
}
async deleteIssue(owner: string, repo: string, issueNumber: number): Promise<void> {
if (this.forceMode === "gh-cli") {
this.requireGh();
runGh(["issue", "delete", String(issueNumber), "--repo", `${owner}/${repo}`, "--yes"]);
return;
}
if (this.forceMode === "token") {
throw new Error("Deleting GitHub issues requires gh CLI authentication. Token-only mode does not support issue deletion.");
}
if (this.hasGhAuth()) {
runGh(["issue", "delete", String(issueNumber), "--repo", `${owner}/${repo}`, "--yes"]);
return;
}
throw new Error("Deleting GitHub issues requires gh CLI authentication. Configure gh auth and retry.");
}
/**
* Fetch current issue status using gh CLI if available, otherwise REST API.
* Returns null if the issue is not found or is a pull request.