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
2import * as Effect from "effect/Effect";2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";3import * as Layer from "effect/Layer";
4import * as Option from "effect/Option";4import * as Option from "effect/Option";
5import { ChildProcessSpawner } from "effect/unstable/process";
5 6
6import * as GitLabCli from "./GitLabCli.ts";7import * as GitLabCli from "./GitLabCli.ts";
8import { parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
7import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";9import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
8 10
9function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) {11function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) {
@@ -107,3 +109,73 @@ it.effect("creates GitLab MRs through provider-neutral input names", () => · 97 unmodified lines
107 });109 });
108 }),110 }),
109);111);
112
113it("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
119self-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
140it("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
169it("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
173selfhosted
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