Showing the changes to apps/server/src/sourceControl/GitLabSourceControlProvider.ts (1 of 42 files). Show all
Unified · Split
| @@ -5,7 +5,16 @@ import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contrac · 4 unmodified lines | |||
| 5 | 5 | ||
| 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 { |
| 9 | combinedAuthOutput, | ||
| 10 | firstSafeAuthLine, | ||
| 11 | matchFirst, | ||
| 12 | parseCliHost, | ||
| 13 | providerAuth, | ||
| 14 | type SourceControlAuthProbeInput, | ||
| 15 | type SourceControlCliDiscoverySpec, | ||
| 16 | type SourceControlUnknownRemoteRefinementInput, | ||
| 17 | } from "./SourceControlProviderDiscovery.ts"; | ||
| 9 | import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts"; | 18 | import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts"; |
| 10 | 19 | ||
| 11 | function providerError( | 20 | function providerError( |
| @@ -42,48 +51,42 @@ function toChangeRequest(summary: GitLabCli.GitLabMergeRequestSummary): ChangeRe · 30 unmodified lines | |||
| 42 | }; | 51 | }; |
| 43 | } | 52 | } |
| 44 | 53 | ||
| 45 | function parseGitLabAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) { | 54 | function parseGitLabAuth(input: SourceControlAuthProbeInput) { |
| 46 | const output = SourceControlProviderDiscovery.combinedAuthOutput(input); | 55 | const output = combinedAuthOutput(input); |
| 47 | const authenticatedHost = findAuthenticatedGitLabHost(parseGitLabAuthStatusHosts(output)); | 56 | const authenticatedHost = findAuthenticatedGitLabHost(parseGitLabAuthStatusHosts(output)); |
| 48 | const account = | 57 | const account = |
| 49 | authenticatedHost?.account ?? | 58 | authenticatedHost?.account ?? |
| 50 | SourceControlProviderDiscovery.matchFirst(output, [ | 59 | matchFirst(output, [ |
| 51 | /Logged in to .* as\s+([^\s(]+)/iu, | 60 | /Logged in to .* as\s+([^\s(]+)/iu, |
| 52 | /Logged in to .* account\s+([^\s(]+)/iu, | 61 | /Logged in to .* account\s+([^\s(]+)/iu, |
| 53 | /account:\s*([^\s(]+)/iu, | 62 | /account:\s*([^\s(]+)/iu, |
| 54 | ]); | 63 | ]); |
| 55 | const host = authenticatedHost?.host ?? SourceControlProviderDiscovery.parseCliHost(output); | 64 | const host = authenticatedHost?.host ?? parseCliHost(output); |
| 56 | 65 | ||
| 57 | if (account) { | 66 | if (account) { |
| 58 | return SourceControlProviderDiscovery.providerAuth({ status: "authenticated", account, host }); | 67 | return providerAuth({ status: "authenticated", account, host }); |
| 59 | } | 68 | } |
| 60 | 69 | ||
| 61 | if (input.exitCode !== 0) { | 70 | if (input.exitCode !== 0) { |
| 62 | return SourceControlProviderDiscovery.providerAuth({ | 71 | return providerAuth({ |
| 63 | status: "unauthenticated", | 72 | status: "unauthenticated", |
| 64 | host, | 73 | host, |
| 65 | detail: | 74 | detail: firstSafeAuthLine(output) ?? "Run `glab auth login` to authenticate GitLab CLI.", |
| 66 | SourceControlProviderDiscovery.firstSafeAuthLine(output) ?? | ||
| 67 | "Run `glab auth login` to authenticate GitLab CLI.", | ||
| 68 | }); | 75 | }); |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | return SourceControlProviderDiscovery.providerAuth({ | 78 | return providerAuth({ |
| 72 | status: "unknown", | 79 | status: "unknown", |
| 73 | host, | 80 | host, |
| 74 | detail: | 81 | detail: firstSafeAuthLine(output) ?? "GitLab CLI auth status could not be parsed.", |
| 75 | SourceControlProviderDiscovery.firstSafeAuthLine(output) ?? | ||
| 76 | "GitLab CLI auth status could not be parsed.", | ||
| 77 | }); | 82 | }); |
| 78 | } | 83 | } |
| 79 | 84 | ||
| 80 | function refineUnknownGitLabRemote( | 85 | function refineUnknownGitLabRemote(input: SourceControlUnknownRemoteRefinementInput) { |
| 81 | input: SourceControlProviderDiscovery.SourceControlUnknownRemoteRefinementInput, | ||
| 82 | ) { | ||
| 83 | const host = input.context.provider.name.toLowerCase(); | 86 | const host = input.context.provider.name.toLowerCase(); |
| 84 | const authenticated = parseGitLabAuthStatusHosts( | 87 | const authenticated = parseGitLabAuthStatusHosts(combinedAuthOutput(input.auth)).some( |
| 85 | SourceControlProviderDiscovery.combinedAuthOutput(input.auth), | 88 | (entry) => entry.account !== null && entry.host === host, |
| 86 | ).some((entry) => entry.account !== null && entry.host === host); | 89 | ); |
| 87 | 90 | ||
| 88 | if (!authenticated) { | 91 | if (!authenticated) { |
| 89 | return null; | 92 | return null; |
| @@ -107,9 +110,9 @@ export const discovery = { · 17 unmodified lines | |||
| 107 | refineUnknownRemote: refineUnknownGitLabRemote, | 110 | refineUnknownRemote: refineUnknownGitLabRemote, |
| 108 | installHint: | 111 | installHint: |
| 109 | "Install the GitLab command-line tool (`glab`) from https://gitlab.com/gitlab-org/cli or your package manager (for example `brew install glab`).", | 112 | "Install the GitLab command-line tool (`glab`) from https://gitlab.com/gitlab-org/cli or your package manager (for example `brew install glab`).", |
| 110 | } satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec; | 113 | } satisfies SourceControlCliDiscoverySpec; |
| 111 | 114 | ||
| 112 | export const make = Effect.fn("makeGitLabSourceControlProvider")(function* () { | 115 | export const make = Effect.gen(function* () { |
| 113 | const gitlab = yield* GitLabCli.GitLabCli; | 116 | const gitlab = yield* GitLabCli.GitLabCli; |
| 114 | 117 | ||
| 115 | return SourceControlProvider.SourceControlProvider.of({ | 118 | return SourceControlProvider.SourceControlProvider.of({ |
| @@ -167,4 +170,4 @@ export const make = Effect.fn("makeGitLabSourceControlProvider")(function* () { · 51 unmodified lines | |||
| 167 | }); | 170 | }); |
| 168 | }); | 171 | }); |
| 169 | 172 | ||
| 170 | export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make()); | 173 | export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make); |