20b08b5321
* add "Rerun failed job" link to error comment footer * Remove issueNumber guard from rerun link The rerun action only needs run_id — the issue number in the trigger URL path is just a route segment requirement. Use 0 as a fallback so the link is always shown when a run ID is available. * Overload `[number]` path segment as `runId` for the rerun action For the rerun trigger, the `[number]` path param now carries the workflow run ID instead of an issue number. The rerun link changes from `/trigger/o/r/ISSUE?action=rerun&run_id=RID` to `/trigger/o/r/RID?action=rerun`. - Remove `run_id` query param from page.tsx and searchParams type - Add error handling around `reRunWorkflow` for invalid run IDs - Drop `issueNumber` from `BuildErrorCommentBodyParams` and all rerun link builders (errorReport, exitHandler, postCleanup) * Reorder validation: action first, then rerun, then issueNumber * address review: remove early toolState assignment, restructure rerun into dedicated block * revert self-contained rerun block, share auth logic via issueOrRunId * improve error handling * normalize runid early --------- Co-authored-by: pullfrog[bot] <226033991+pullfrog[bot]@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import type { ToolState } from "../mcp/server.ts";
|
|
import { getApiUrl } from "./apiUrl.ts";
|
|
import { buildPullfrogFooter } from "./buildPullfrogFooter.ts";
|
|
import { createOctokit, parseRepoContext } from "./github.ts";
|
|
import { getGitHubInstallationToken } from "./token.ts";
|
|
|
|
interface ReportErrorParams {
|
|
toolState: ToolState;
|
|
error: string;
|
|
title?: string;
|
|
}
|
|
|
|
export async function reportErrorToComment(ctx: ReportErrorParams): Promise<void> {
|
|
const formattedError = ctx.title ? `${ctx.title}\n\n${ctx.error}` : ctx.error;
|
|
|
|
const commentId = ctx.toolState.progressCommentId;
|
|
if (!commentId) {
|
|
return;
|
|
}
|
|
|
|
const repoContext = parseRepoContext();
|
|
const octokit = createOctokit(getGitHubInstallationToken());
|
|
const runId = process.env.GITHUB_RUN_ID
|
|
? Number.parseInt(process.env.GITHUB_RUN_ID, 10)
|
|
: undefined;
|
|
|
|
const customParts: string[] = [];
|
|
if (runId) {
|
|
const apiUrl = getApiUrl();
|
|
customParts.push(
|
|
`[Rerun failed job ➔](${apiUrl}/trigger/${repoContext.owner}/${repoContext.name}/${runId}?action=rerun)`
|
|
);
|
|
}
|
|
|
|
const footer = buildPullfrogFooter({
|
|
triggeredBy: true,
|
|
workflowRun: runId ? { owner: repoContext.owner, repo: repoContext.name, runId } : undefined,
|
|
customParts,
|
|
});
|
|
|
|
await octokit.rest.issues.updateComment({
|
|
owner: repoContext.owner,
|
|
repo: repoContext.name,
|
|
comment_id: commentId,
|
|
body: `${formattedError}${footer}`,
|
|
});
|
|
|
|
// mark as updated so exit handler doesn't try to update again
|
|
ctx.toolState.wasUpdated = true;
|
|
}
|