Skip to content

Commit 8a773f0

Browse files
committed
fix(gitlab): preserve rate limits when reading thread refs
1 parent fac7f71 commit 8a773f0

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
930930
);
931931

932932
it.effect(
933-
"keeps discussions current when the merge request's diff refs are missing or unreadable",
933+
"keeps discussions current for unreadable refs but propagates CLI requirements and rate limits",
934934
() =>
935935
Effect.gen(function* () {
936936
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
@@ -971,6 +971,29 @@ layer("GitLabPullRequestCli.layer", (it) => {
971971

972972
expect(threads.map((thread) => [thread.id, thread.isOutdated])).toEqual([["abc", false]]);
973973
}
974+
const context = {
975+
operation: "execute" as const,
976+
command: "glab" as const,
977+
cwd: "/w",
978+
cause: new Error("unavailable"),
979+
};
980+
for (const error of [
981+
new GitLabCli.GitLabCliUnavailableError(context),
982+
new GitLabCli.GitLabCliAuthenticationError(context),
983+
new GitLabCli.GitLabCliRateLimitError(context),
984+
]) {
985+
mockedExecute.mockImplementation(({ args }) =>
986+
args[1]?.includes("/discussions") ? Effect.succeed(output("[]")) : Effect.fail(error),
987+
);
988+
expect(
989+
yield* Effect.result(
990+
cli.listDiscussions({ cwd: "/w", repository: "acme/web", number: 7 }),
991+
),
992+
).toMatchObject({
993+
_tag: "Failure",
994+
failure: error,
995+
});
996+
}
974997
}),
975998
);
976999

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,16 @@ export const make = Effect.gen(function* () {
17311731
discussionsPage({ ...input, page: 1, collected: [], diffRefsByThreadId: new Map() }),
17321732
// Fresh beside the discussions: cached refs from before a push would invert every flag.
17331733
// Unreadable refs leave threads current rather than hiding them.
1734-
getDiffRefs(input).pipe(Effect.orElseSucceed(() => null)),
1734+
getDiffRefs(input).pipe(
1735+
Effect.catchTags(
1736+
{
1737+
GitLabCliUnavailableError: (error) => Effect.fail(error),
1738+
GitLabCliAuthenticationError: (error) => Effect.fail(error),
1739+
GitLabCliRateLimitError: (error) => Effect.fail(error),
1740+
},
1741+
() => Effect.succeed(null),
1742+
),
1743+
),
17351744
],
17361745
{ concurrency: 2 },
17371746
);

0 commit comments

Comments
 (0)