diff --git a/packages/source-control-github/src/server/GitHubPullRequestApi.test.ts b/packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
index aff9f9c627a1a..c3cc15097dfd5 100644
--- a/packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
+++ b/packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
@@ -838,6 +838,27 @@ layer("GitHubPullRequestApi.layer", (it) => {
}),
);
}
+ // Job 16 never started, so GitHub holds no log; its check run explains why.
+ if (log?.[1] === "16") {
+ return Effect.fail(
+ new GitHubRequestPolicy.GitHubApiNotFoundError({
+ host: "github.com",
+ operation: "readCheckLog",
+ }),
+ );
+ }
+ if (/check-runs\/16\/annotations/.test(call.path)) {
+ return Effect.succeed(
+ output(
+ encodeJson([
+ {
+ annotation_level: "failure",
+ message: "The job was not started because of a billing problem.",
+ },
+ ]),
+ ),
+ );
+ }
if (log) return Effect.succeed(output("setup\nbuild\nError: boom\n"));
const job = /actions\/jobs\/(\d+)$/.exec(call.path);
if (job) return Effect.succeed(output(encodeJson({ run_id: runOf[job[1]!] })));
@@ -871,6 +892,8 @@ layer("GitHubPullRequestApi.layer", (it) => {
{ log: "one long line", truncated: true },
]);
const refused = yield* Effect.flip(api.readCheckLogs({ ...capped, checks: [job(14, 30)] }));
+ const [unstarted] = yield* api.readCheckLogs({ ...capped, checks: [job(16, 30)] });
+ expect(unstarted?.detail).toContain("The job was not started because of a billing problem.");
const [huge] = yield* api.readCheckLogs({ ...capped, checks: [job(15, 30)] });
expect(huge?.log?.length).toBe(32_000);
expect(huge?.truncated).toBe(true);
diff --git a/packages/source-control-github/src/server/GitHubPullRequestApi.ts b/packages/source-control-github/src/server/GitHubPullRequestApi.ts
index e3a5483261610..0f6b76dd5040c 100644
--- a/packages/source-control-github/src/server/GitHubPullRequestApi.ts
+++ b/packages/source-control-github/src/server/GitHubPullRequestApi.ts
@@ -876,6 +876,29 @@ const decodeRunJobs = Schema.decodeEffect(
}),
),
);
+const decodeCheckRun = Schema.decodeEffect(
+ Schema.fromJsonString(
+ Schema.Struct({
+ conclusion: Schema.optional(Schema.NullOr(Schema.String)),
+ output: Schema.optional(
+ Schema.Struct({
+ title: Schema.optional(Schema.NullOr(Schema.String)),
+ summary: Schema.optional(Schema.NullOr(Schema.String)),
+ }),
+ ),
+ }),
+ ),
+);
+const decodeCheckRunAnnotations = Schema.decodeEffect(
+ Schema.fromJsonString(
+ Schema.Array(
+ Schema.Struct({
+ annotation_level: Schema.optional(Schema.NullOr(Schema.String)),
+ message: Schema.String,
+ }),
+ ),
+ ),
+);
const FAILED_CONCLUSIONS = new Set(["failure", "cancelled", "timed_out", "startup_failure"]);
const ONE_JOB_AT_A_TIME =
"GitHub re-runs one job of a run at a time. Re-run this one after the other finishes.";
@@ -2912,6 +2935,43 @@ export const make = Effect.gen(function* () {
readCheckLogs: Effect.fn("GitHubPullRequestApi.readCheckLogs")(function* (input) {
const { owner, name } = parseRepositorySelector(input.repository);
+ const readCheckRun = (path: string, decode: (body: string) => Effect.Effect) =>
+ api
+ .rest({ host: input.host, operation: "readCheckRun", path })
+ .pipe(Effect.flatMap((response) => decode(response.body)));
+ // A job that never started (billing block, skipped) or whose log expired has no log;
+ // its check run (an Actions job id is its check run id) says why.
+ const missingLog = (check: ProviderCheckReference, jobId: string, fallback: string) =>
+ Effect.all(
+ [
+ readCheckRun(`repos/${owner}/${name}/check-runs/${jobId}`, decodeCheckRun),
+ readCheckRun(
+ `repos/${owner}/${name}/check-runs/${jobId}/annotations?per_page=50`,
+ decodeCheckRunAnnotations,
+ ),
+ ],
+ { concurrency: 2 },
+ ).pipe(
+ Effect.map(([run, annotations]) =>
+ [
+ `GitHub returned no log for this job${run.conclusion ? `; it concluded ${run.conclusion}` : ""}.`,
+ run.output?.title,
+ run.output?.summary,
+ ...annotations.map(
+ (annotation) =>
+ `${annotation.annotation_level ? `${annotation.annotation_level}: ` : ""}${annotation.message}`,
+ ),
+ ]
+ .filter((line) => typeof line === "string" && line.trim() !== "")
+ .join("\n"),
+ ),
+ Effect.catchTags({
+ GitHubApiNotFoundError: () => Effect.succeed(fallback),
+ GitHubApiResponseError: () => Effect.succeed(fallback),
+ SchemaError: () => Effect.succeed(fallback),
+ }),
+ Effect.map((detail) => ({ ...check, log: null, truncated: false, detail })),
+ );
return yield* Effect.forEach(
input.checks,
(check) => {
@@ -2947,10 +3007,8 @@ export const make = Effect.gen(function* () {
}),
// Sign-in and rate-limit failures fail the call; the rest are this check's.
Effect.catchTags({
- GitHubApiNotFoundError: (error) =>
- Effect.succeed({ ...check, log: null, truncated: false, detail: error.message }),
- GitHubApiResponseError: (error) =>
- Effect.succeed({ ...check, log: null, truncated: false, detail: error.message }),
+ GitHubApiNotFoundError: (error) => missingLog(check, jobId, error.message),
+ GitHubApiResponseError: (error) => missingLog(check, jobId, error.message),
}),
);
},