Skip to content

Commit 71a283a

Browse files
Mnigosjuliusmarmingeclaude
authored
fix(server): Forgejo skipped jobs no longer keep a pull request watch pending (#16668)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 7e52513 commit 71a283a

2 files changed

Lines changed: 82 additions & 6 deletions

File tree

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,67 @@ it.effect.each([
278278
}).pipe(Effect.provide(requiredChecksLayer(Effect.fail(cause))));
279279
});
280280

281+
it.effect("reads Forgejo jobs that did not run as finished checks", () =>
282+
Effect.gen(function* () {
283+
const provider = yield* ForgejoPullRequestProvider.make;
284+
const read = provider.getChangeRequestChecks;
285+
if (read === undefined) return yield* Effect.die("checks read missing");
286+
const result = yield* read({
287+
cwd: "/repo",
288+
repository: "acme/web",
289+
host: "forgejo.test",
290+
number: 1,
291+
});
292+
assert.deepStrictEqual(
293+
result.checks.map((check) => [check.name, check.status]),
294+
[
295+
["deploy", "skipped"],
296+
["audit", "neutral"],
297+
["docs", "pending"],
298+
],
299+
);
300+
}).pipe(
301+
Effect.provide(
302+
Layer.mock(ForgejoCli.ForgejoCli)({
303+
api: (input) => {
304+
const status = (context: string, state: string) => ({
305+
context,
306+
status: state,
307+
description: null,
308+
target_url: null,
309+
updated_at: "2026-10-11T00:00:00Z",
310+
});
311+
const body = input.path.endsWith("pulls/1")
312+
? {
313+
number: 1,
314+
title: "Checks",
315+
body: "",
316+
html_url: "https://forgejo.test/acme/web/pulls/1",
317+
user: null,
318+
state: "open",
319+
merged: false,
320+
head: { ref: "feature", sha: "head", repo: null },
321+
base: { ref: "main", sha: "base", repo: null },
322+
created_at: "2026-10-11T00:00:00Z",
323+
updated_at: "2026-10-11T00:00:00Z",
324+
closed_at: null,
325+
merged_at: null,
326+
labels: [],
327+
}
328+
: input.path.endsWith("page=1")
329+
? [
330+
status("deploy", "skipped"),
331+
status("audit", "warning"),
332+
status("docs", "future-state"),
333+
]
334+
: [];
335+
return encodeJsonEffect(body).pipe(Effect.orDie, Effect.map(processOutput));
336+
},
337+
}),
338+
),
339+
),
340+
);
341+
281342
it.effect("opens Forgejo Actions check links on the pull request's server", () =>
282343
Effect.gen(function* () {
283344
const provider = yield* ForgejoPullRequestProvider.make;

‎packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Option from "effect/Option";
44
import type {
55
PullRequestActor,
66
PullRequestCheck,
7+
PullRequestCheckStatus,
78
PullRequestComment,
89
PullRequestCommit,
910
PullRequestReaction,
@@ -213,6 +214,25 @@ export function forgejoCommit(commit: typeof ForgejoCommit.Type): PullRequestCom
213214
};
214215
}
215216

217+
// Forgejo Actions reports a job that did not run as `skipped` and a cancelled one as `failure`,
218+
// and `warning` is finished without being a pass. Only `pending` and states we do not know may
219+
// hold a watch open.
220+
function forgejoCheckStatus(state: string): PullRequestCheckStatus {
221+
switch (state) {
222+
case "success":
223+
return "success";
224+
case "failure":
225+
case "error":
226+
return "failure";
227+
case "skipped":
228+
return "skipped";
229+
case "warning":
230+
return "neutral";
231+
default:
232+
return "pending";
233+
}
234+
}
235+
216236
export function forgejoChecks(
217237
statuses: ReadonlyArray<typeof ForgejoStatus.Type>,
218238
pullRequestUrl: string,
@@ -227,12 +247,7 @@ export function forgejoChecks(
227247
url: status.target_url
228248
? (URL.parse(status.target_url, pullRequestUrl)?.href ?? null)
229249
: null,
230-
status:
231-
status.status === "success"
232-
? "success"
233-
: status.status === "failure" || status.status === "error"
234-
? "failure"
235-
: "pending",
250+
status: forgejoCheckStatus(status.status),
236251
},
237252
})),
238253
);

0 commit comments

Comments
 (0)