Skip to content

Commit 4218576

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): keep each GitLab host's finished pipeline checks apart
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9ac3a95 commit 4218576

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎apps/server/src/pullRequest/GitLabPullRequestCli.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
902902
readonly bridges: string | ReadonlyArray<string>;
903903
},
904904
pipeline: Record<string, unknown> = headPipeline,
905+
mergeRequest: Record<string, unknown> = {},
905906
) {
906907
mockedExecute.mockImplementation((input) => {
907908
const path = input.args[1] ?? "";
@@ -911,7 +912,9 @@ layer("GitLabPullRequestCli.layer", (it) => {
911912
? "bridges"
912913
: null;
913914
if (kind === null) {
914-
return Effect.succeed(output(mergeRequestJson({ head_pipeline: pipeline })));
915+
return Effect.succeed(
916+
output(mergeRequestJson({ ...mergeRequest, head_pipeline: pipeline })),
917+
);
915918
}
916919
const pages = lists[kind];
917920
const page = Number(new URLSearchParams(path.split("?")[1]).get("page"));
@@ -1019,6 +1022,22 @@ layer("GitLabPullRequestCli.layer", (it) => {
10191022
}),
10201023
);
10211024

1025+
it.effect("keeps a finished pipeline's checks apart from another GitLab's", () =>
1026+
Effect.gen(function* () {
1027+
const pipeline = { ...headPipeline, id: 230 };
1028+
answer({ jobs: pageOf(1, 2), bridges: "[]" }, pipeline);
1029+
yield* read(true);
1030+
1031+
// The same ids on a self-managed GitLab name a different pipeline.
1032+
answer({ jobs: pageOf(1, 3), bridges: "[]" }, pipeline, {
1033+
web_url: "https://gitlab.example.com/acme/web/-/merge_requests/7",
1034+
});
1035+
const other = yield* read(true);
1036+
expect(jobReads()).toBe(4);
1037+
expect(other.checks).toHaveLength(3);
1038+
}),
1039+
);
1040+
10221041
it.effect("reads a finished pipeline's jobs again after a partial read", () =>
10231042
Effect.gen(function* () {
10241043
const pipeline = { ...headPipeline, id: 250 };

‎apps/server/src/pullRequest/GitLabPullRequestCli.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,9 @@ export const make = Effect.gen(function* () {
927927
);
928928

929929
/**
930-
* The checks of finished pipelines, by pipeline and the moment it settled. A finished
930+
* The checks of finished pipelines, by the merge request that showed them, the pipeline and
931+
* the moment it settled. The merge request's URL names its host, and ids are only unique
932+
* within one GitLab, so a server reading from several never answers one from another. A finished
931933
* pipeline's jobs do not change until it runs again, and that moves the moment, so every
932934
* refresh of a merge request whose pipeline is done costs no job reads. Only whole job lists
933935
* are kept: a read that failed, came back partial or found no jobs is tried again. A
@@ -994,7 +996,7 @@ export const make = Effect.gen(function* () {
994996
const settledKey =
995997
pipeline.settledAt === null
996998
? null
997-
: `${pipeline.projectId}/${pipeline.id}@${pipeline.settledAt}`;
999+
: `${detail.url}#${pipeline.projectId}/${pipeline.id}@${pipeline.settledAt}`;
9981000
const settled = settledKey === null ? undefined : settledPipelineChecks.get(settledKey);
9991001
if (settled !== undefined) {
10001002
return Effect.succeed({ ...detail, checks: settled });

0 commit comments

Comments
 (0)