Skip to content
TypeScript

fix(gitlab): report an expired glab OAuth login as an auth error (#27511)

Daniel Walsh84ad7aef6a70
diff --git a/packages/source-control-gitlab/src/server/GitLabCli.test.ts b/packages/source-control-gitlab/src/server/GitLabCli.test.ts
index a0609421e12..dca21820621 100644
--- a/packages/source-control-gitlab/src/server/GitLabCli.test.ts
+++ b/packages/source-control-gitlab/src/server/GitLabCli.test.ts
@@ -82,6 +82,19 @@ layer("GitLabCli.layer", (it) => {
args: ["mr", "view", "--output", "json", "--", "42"],
}),
);
+ const classifyFailure = mockedRun.mock.calls.at(-1)?.[0].classifyFailure;
+ assert.strictEqual(
+ classifyFailure?.(
+ "x gitlab.example.test has not been authenticated with glab. Run `glab auth login`",
+ ),
+ "authentication",
+ );
+ assert.strictEqual(
+ classifyFailure?.(
+ 'Failed to get merge request 42: oauth2: "invalid_grant" "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."',
+ ),
+ "authentication",
+ );
}),
);
diff --git a/packages/source-control-gitlab/src/server/GitLabCli.ts b/packages/source-control-gitlab/src/server/GitLabCli.ts
index 0368395a6fa..7690304897a 100644
--- a/packages/source-control-gitlab/src/server/GitLabCli.ts
+++ b/packages/source-control-gitlab/src/server/GitLabCli.ts
@@ -411,11 +411,18 @@ function parseRepositoryPath(repository: string): {
return { namespacePath, projectPath };
}
-// glab prints a missing project or merge request as a bare 404.
+// glab prints a missing project or merge request as a bare 404, and an expired
+// OAuth login as an `invalid_grant` refresh failure without suggesting `glab auth login`.
const classifyGlabFailure = (stderr: string): VcsProcessExitFailureKind | null => {
const normalized = stderr.toLowerCase();
- if (normalized.includes("glab auth login")) return "authentication";
- if (normalized.includes("not found") || normalized.includes("404")) return "not-found";
+ if (normalized.includes("glab auth login") || normalized.includes("invalid_grant")) {
+ return "authentication";
+ }
+
+ if (normalized.includes("not found") || normalized.includes("404")) {
+ return "not-found";
+ }
+
return null;
};