History

fix(source-control): handle self-hosted GitLab, multi-account GitHub auth & azure devops web url (#2480)

Guilherme Vieira committed 5 months ago

Commit 49c1b641 parent dfdb5a414 files · +757 −48Browse files

Showing the changes to apps/server/src/sourceControl/GitLabSourceControlProvider.test.ts (1 of 14 files). Show all

Unified · Split

apps/server/src/sourceControl/GitLabSourceControlProvider.test.ts+72−0
@@ -2,8 +2,10 @@ import { assert, it } from "@effect/vitest"; · 1 unmodified line
22 import * as Effect from "effect/Effect";
33 import * as Layer from "effect/Layer";
44 import * as Option from "effect/Option";
5+import { ChildProcessSpawner } from "effect/unstable/process";
56
67 import * as GitLabCli from "./GitLabCli.ts";
8+import { parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
79 import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
810
911 function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) {
@@ -107,3 +109,73 @@ it.effect("creates GitLab MRs through provider-neutral input names", () => · 97 unmodified lines
107109 });
108110 }),
109111 );
112+
113+it("accepts authenticated GitLab hosts when another configured host fails", () => {
114+ const auth = GitLabSourceControlProvider.discovery.parseAuth({
115+ exitCode: ChildProcessSpawner.ExitCode(1),
116+ stdout: `gitlab.com
117+ x gitlab.com: API call failed: 401 Unauthorized
118+ ! No token found
119+self-hosted.example.test
120+ ✓ Logged in to self-hosted.example.test as gitlab-user
121+ ✓ Token found: ******
122+`,
123+ stderr: "",
124+ });
125+
126+ assert.deepStrictEqual(
127+ {
128+ status: auth.status,
129+ account: auth.account,
130+ host: auth.host,
131+ },
132+ {
133+ status: "authenticated",
134+ account: Option.some("gitlab-user"),
135+ host: Option.some("self-hosted.example.test"),
136+ },
137+ );
138+});
139+
140+it("refines unknown GitLab remotes with mixed-case provider hosts", () => {
141+ const provider = GitLabSourceControlProvider.discovery.refineUnknownRemote?.({
142+ cwd: "/repo",
143+ context: {
144+ provider: {
145+ kind: "unknown",
146+ name: "Self-Hosted.Example.Test",
147+ baseUrl: "https://Self-Hosted.Example.Test",
148+ },
149+ remoteName: "origin",
150+ remoteUrl: "https://Self-Hosted.Example.Test/group/project.git",
151+ },
152+ auth: {
153+ exitCode: ChildProcessSpawner.ExitCode(0),
154+ stdout: `self-hosted.example.test
155+ ✓ Logged in to self-hosted.example.test as gitlab-user
156+ ✓ Token found: ******
157+`,
158+ stderr: "",
159+ },
160+ });
161+
162+ assert.deepStrictEqual(provider, {
163+ kind: "gitlab",
164+ name: "GitLab Self-Hosted",
165+ baseUrl: "https://Self-Hosted.Example.Test",
166+ });
167+});
168+
169+it("parses authenticated GitLab auth status hosts with ports and single-label names", () => {
170+ assert.deepStrictEqual(
171+ parseGitLabAuthStatusHosts(`localhost:8080
172+ ✓ Logged in to localhost:8080 as local-user
173+selfhosted
174+ ✓ Logged in to selfhosted as single-label-user
175+`),
176+ [
177+ { host: "localhost:8080", account: "local-user" },
178+ { host: "selfhosted", account: "single-label-user" },
179+ ],
180+ );
181+});

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t