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 | import * as GitLabCli from "./GitLabCli.ts"; | 6 | import * as GitLabCli from "./GitLabCli.ts"; |
| 7 | import * as SourceControlProvider from "./SourceControlProvider.ts"; | 7 | import * as SourceControlProvider from "./SourceControlProvider.ts"; |
| 8 | import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts"; | 8 | import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts"; |
| 9 | import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts"; | ||
| 9 | 10 | ||
| 10 | function providerError( | 11 | function providerError( |
| 11 | operation: string, | 12 | operation: string, |
| @@ -43,12 +44,19 @@ function toChangeRequest(summary: GitLabCli.GitLabMergeRequestSummary): ChangeRe · 31 unmodified lines | |||
| 43 | 44 | ||
| 44 | function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) { | 45 | function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) { |
| 45 | const output = SourceControlProviderDiscovery.combinedAuthOutput(input); | 46 | const output = SourceControlProviderDiscovery.combinedAuthOutput(input); |
| 46 | const account = SourceControlProviderDiscovery.matchFirst(output, [ | 47 | const authenticatedHost = findAuthenticatedGitLabHost(parseGitLabAuthStatusHosts(output)); |
| 47 | /Logged in to .* as\s+([^\s(]+)/iu, | 48 | const account = |
| 48 | /Logged in to .* account\s+([^\s(]+)/iu, | 49 | authenticatedHost?.account ?? |
| 49 | /account:\s*([^\s(]+)/iu, | 50 | SourceControlProviderDiscovery.matchFirst(output, [ |
| 50 | ]); | 51 | /Logged in to .* as\s+([^\s(]+)/iu, |
| 51 | const host = SourceControlProviderDiscovery.parseCliHost(output); | 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 | if (input.exitCode !== 0) { | 61 | if (input.exitCode !== 0) { |
| 54 | return SourceControlProviderDiscovery.providerAuth({ | 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 | return SourceControlProviderDiscovery.providerAuth({ | 71 | return SourceControlProviderDiscovery.providerAuth({ |
| 68 | status: "unknown", | 72 | status: "unknown", |
| 69 | host, | 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 | export const discovery = { | 99 | export const discovery = { |
| 77 | type: "cli", | 100 | type: "cli", |
| 78 | kind: "gitlab", | 101 | kind: "gitlab", |
| @@ -81,6 +104,7 @@ export const discovery = { · 2 unmodified lines | |||
| 81 | versionArgs: ["--version"], | 104 | versionArgs: ["--version"], |
| 82 | authArgs: ["auth", "status"], | 105 | authArgs: ["auth", "status"], |
| 83 | parseAuth: parseGitLabAuth, | 106 | parseAuth: parseGitLabAuth, |
| 107 | refineUnknownRemote: refineUnknownGitLabRemote, | ||
| 84 | installHint: | 108 | installHint: |
| 85 | "Install the GitLab command-line tool (`glab`) from https://gitlab.com/gitlab-org/cli or your package manager (for example `brew install glab`).", | 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 | } satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec; | 110 | } satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec; |