Skip to content

Commit 3bfbe59

Browse files
committed
fix(server): recognize GitHub HTTP 404 stack responses
1 parent d6f2913 commit 3bfbe59

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

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

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as TestClock from "effect/testing/TestClock";
99
import { ChildProcessSpawner } from "effect/unstable/process";
1010

1111
import * as GitHubCli from "../sourceControl/GitHubCli.ts";
12+
import * as ProcessRunner from "../processRunner.ts";
1213
import * as VcsProcess from "../vcs/VcsProcess.ts";
1314
import * as SourceControlRateLimit from "../sourceControl/SourceControlRateLimit.ts";
1415
import * as GitHubGraphQlBudget from "../sourceControl/githubGraphQlBudget.ts";
@@ -650,28 +651,51 @@ layer("GitHubPullRequestCli.layer", (it) => {
650651
}),
651652
);
652653

653-
it.effect("reads a host that refuses the stacks preview as not stacked", () =>
654+
it.effect.each([
655+
["gh: Not Found (HTTP 404)", null],
656+
["HTTP 404: Not Found (https://github.example/api/v3/repos/acme/web/stacks)", null],
657+
["gh: Resource not accessible by integration (HTTP 403)", "GitHubCliCommandError"],
658+
["gh: Service Unavailable (HTTP 503)", "GitHubCliCommandError"],
659+
["dial tcp: lookup github.example: no such host", "GitHubCliCommandError"],
660+
["To get started with GitHub CLI, please run: gh auth login", "GitHubCliAuthenticationError"],
661+
["gh: Too Many Requests (HTTP 429)", "GitHubCliRateLimitError"],
662+
] as const)("classifies the raw stacks API failure: %s", ([stderr, expectedError]) =>
654663
Effect.gen(function* () {
655-
// The CLI classifies a missing preview endpoint as not found.
656-
mockedExecute.mockReturnValueOnce(
657-
Effect.fail(
658-
new GitHubCli.GitHubPullRequestNotFoundError({
659-
command: "gh",
660-
cwd: "/w",
661-
cause: new Error("HTTP 404: Not Found (https://api.github.com/repos/acme/web/stacks)"),
662-
}),
663-
),
664+
const vcs = yield* VcsProcess.make.pipe(
665+
Effect.provideService(ProcessRunner.ProcessRunner, {
666+
run: () =>
667+
Effect.succeed({
668+
stdout: "",
669+
stderr,
670+
code: ChildProcessSpawner.ExitCode(1),
671+
timedOut: false,
672+
stdoutTruncated: false,
673+
stderrTruncated: false,
674+
stdoutInvalidUtf8: false,
675+
stderrInvalidUtf8: false,
676+
}),
677+
}),
664678
);
665-
const cli = yield* GitHubPullRequestCli.GitHubPullRequestCli;
666-
667-
const stack = yield* cli.getPullRequestStack({
679+
const github = yield* GitHubCli.make.pipe(
680+
Effect.provideService(VcsProcess.VcsProcess, vcs),
681+
Effect.provide(Layer.merge(GitHubGraphQlBudget.layer, SourceControlRateLimit.layer)),
682+
);
683+
const cli = yield* GitHubPullRequestCli.make.pipe(
684+
Effect.provideService(GitHubCli.GitHubCli, github),
685+
Effect.provide(GitHubGraphQlBudget.layer),
686+
);
687+
const read = cli.getPullRequestStack({
668688
cwd: "/w",
669689
repository: "acme/web",
670-
host: "github.com",
690+
host: "github.example",
671691
number: 7,
672692
});
673-
674-
assert.isNull(stack);
693+
if (expectedError === null) {
694+
assert.isNull(yield* read);
695+
} else {
696+
const error = yield* Effect.flip(read);
697+
assert.strictEqual(error._tag, expectedError);
698+
}
675699
}),
676700
);
677701

‎apps/server/src/vcs/VcsProcess.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const classifyNonZeroExit = (command: string, stderr: string): VcsProcessExitFai
9393
(normalized.includes("could not resolve to a pullrequest") ||
9494
normalized.includes("repository.pullrequest") ||
9595
normalized.includes("no pull requests found for branch") ||
96+
normalized.includes("http 404") ||
9697
normalized.includes("pull request not found"))) ||
9798
(command === "glab" &&
9899
(normalized.includes("merge request not found") ||

0 commit comments

Comments
 (0)