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>
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { log } from "./cli.ts";
|
|
import type { OctokitWithPlugins } from "./github.ts";
|
|
|
|
interface ResolveRunParams {
|
|
octokit: OctokitWithPlugins;
|
|
}
|
|
|
|
export interface ResolveRunResult {
|
|
runId: number | undefined;
|
|
jobId: string | undefined;
|
|
}
|
|
|
|
/**
|
|
* Resolve GitHub Actions workflow run context.
|
|
* Uses GITHUB_REPOSITORY and GITHUB_RUN_ID env vars.
|
|
*/
|
|
export async function resolveRun(params: ResolveRunParams): Promise<ResolveRunResult> {
|
|
const runId = process.env.GITHUB_RUN_ID
|
|
? Number.parseInt(process.env.GITHUB_RUN_ID, 10)
|
|
: undefined;
|
|
const githubRepo = process.env.GITHUB_REPOSITORY;
|
|
if (!githubRepo || !githubRepo.includes("/")) {
|
|
throw new Error(`GITHUB_REPOSITORY env var must be set to "owner/repo", got: ${githubRepo}`);
|
|
}
|
|
const [owner, repo] = githubRepo.split("/");
|
|
|
|
let jobId: string | undefined;
|
|
const jobName = process.env.GITHUB_JOB;
|
|
if (jobName && runId) {
|
|
const jobs = await params.octokit.rest.actions.listJobsForWorkflowRun({
|
|
owner,
|
|
repo,
|
|
run_id: runId,
|
|
});
|
|
const matchingJob = jobs.data.jobs.find((job) => job.name === jobName);
|
|
if (matchingJob) {
|
|
jobId = String(matchingJob.id);
|
|
log.debug(`» found job ID: ${jobId}`);
|
|
}
|
|
}
|
|
|
|
return { runId, jobId };
|
|
}
|