Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/source-control-gitlab/src/server/GitLabCli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
}),
);

Expand Down
13 changes: 10 additions & 3 deletions packages/source-control-gitlab/src/server/GitLabCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,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;
};

Expand Down
Loading