Showing the changes to apps/server/src/sourceControl/GitLabSourceControlProvider.ts (1 of 14 files). Show all
Unified · Split
| @@ -6,6 +6,7 @@ import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contrac · 5 unmodified lines | ||
| 6 | 6 | import * as GitLabCli from "./GitLabCli.ts"; |
| 7 | 7 | import * as SourceControlProvider from "./SourceControlProvider.ts"; |
| 8 | 8 | import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts"; |
| 9 | +import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts"; | |
| 9 | 10 | |
| 10 | 11 | function providerError( |
| 11 | 12 | operation: string, |
| @@ -43,12 +44,19 @@ function toChangeRequest(summary: GitLabCli.GitLabMergeRequestSummary): ChangeRe · 31 unmodified lines | ||
| 43 | 44 | |
| 44 | 45 | function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) { |
| 45 | 46 | const output = SourceControlProviderDiscovery.combinedAuthOutput(input); |
| 46 | − const account = SourceControlProviderDiscovery.matchFirst(output, [ | |
| 47 | − /Logged in to .* as\s+([^\s(]+)/iu, | |
| 48 | − /Logged in to .* account\s+([^\s(]+)/iu, | |
| 49 | − /account:\s*([^\s(]+)/iu, | |
| 50 | − ]); | |
| 51 | − const host = SourceControlProviderDiscovery.parseCliHost(output); | |
| 47 | + const authenticatedHost = findAuthenticatedGitLabHost(parseGitLabAuthStatusHosts(output)); | |
| 48 | + const account = | |
| 49 | + authenticatedHost?.account ?? | |
| 50 | + SourceControlProviderDiscovery.matchFirst(output, [ | |
| 51 | + /Logged in to .* as\s+([^\s(]+)/iu, | |
| 52 | + /Logged in to .* account\s+([^\s(]+)/iu, | |
| 53 | + /account:\s*([^\s(]+)/iu, | |
| 54 | + ]); | |
| 55 | + const host = authenticatedHost?.host ?? SourceControlProviderDiscovery.parseCliHost(output); | |
| 56 | + | |
| 57 | + if (account) { | |
| 58 | + return SourceControlProviderDiscovery.providerAuth({ status: "authenticated", account, host }); | |
| 59 | + } | |
| 52 | 60 | |
| 53 | 61 | if (input.exitCode !== 0) { |
| 54 | 62 | return SourceControlProviderDiscovery.providerAuth({ |
| @@ -60,10 +68,6 @@ function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuth · 5 unmodified lines | ||
| 60 | 68 | }); |
| 61 | 69 | } |
| 62 | 70 | |
| 63 | − if (account) { | |
| 64 | − return SourceControlProviderDiscovery.providerAuth({ status: "authenticated", account, host }); | |
| 65 | − } | |
| 66 | − | |
| 67 | 71 | return SourceControlProviderDiscovery.providerAuth({ |
| 68 | 72 | status: "unknown", |
| 69 | 73 | host, |
| @@ -73,6 +77,25 @@ function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuth · 3 unmodified lines | ||
| 73 | 77 | }); |
| 74 | 78 | } |
| 75 | 79 | |
| 80 | +function refineUnknownGitLabRemote( | |
| 81 | + input: SourceControlProviderDiscovery.SourceControlUnknownRemoteRefinementInput, | |
| 82 | +) { | |
| 83 | + const host = input.context.provider.name.toLowerCase(); | |
| 84 | + const authenticated = parseGitLabAuthStatusHosts( | |
| 85 | + SourceControlProviderDiscovery.combinedAuthOutput(input.auth), | |
| 86 | + ).some((entry) => entry.account !== null && entry.host === host); | |
| 87 | + | |
| 88 | + if (!authenticated) { | |
| 89 | + return null; | |
| 90 | + } | |
| 91 | + | |
| 92 | + return { | |
| 93 | + kind: "gitlab", | |
| 94 | + name: "GitLab Self-Hosted", | |
| 95 | + baseUrl: input.context.provider.baseUrl, | |
| 96 | + } as const; | |
| 97 | +} | |
| 98 | + | |
| 76 | 99 | export const discovery = { |
| 77 | 100 | type: "cli", |
| 78 | 101 | kind: "gitlab", |
| @@ -81,6 +104,7 @@ export const discovery = { · 2 unmodified lines | ||
| 81 | 104 | versionArgs: ["--version"], |
| 82 | 105 | authArgs: ["auth", "status"], |
| 83 | 106 | parseAuth: parseGitLabAuth, |
| 107 | + refineUnknownRemote: refineUnknownGitLabRemote, | |
| 84 | 108 | installHint: |
| 85 | 109 | "Install the GitLab command-line tool (`glab`) from https://gitlab.com/gitlab-org/cli or your package manager (for example `brew install glab`).", |
| 86 | 110 | } satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec; |