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 | 6 | import * as GitLabCli from "./GitLabCli.ts"; |
| 7 | 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 | 18 | import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts"; |
| 10 | 19 | |
| 11 | 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) { | |
| 46 | − const output = SourceControlProviderDiscovery.combinedAuthOutput(input); | |
| 54 | +function parseGitLabAuth(input: SourceControlAuthProbeInput) { | |
| 55 | + const output = combinedAuthOutput(input); | |
| 47 | 56 | const authenticatedHost = findAuthenticatedGitLabHost(parseGitLabAuthStatusHosts(output)); |
| 48 | 57 | const account = |
| 49 | 58 | authenticatedHost?.account ?? |
| 50 | − SourceControlProviderDiscovery.matchFirst(output, [ | |
| 59 | + matchFirst(output, [ | |
| 51 | 60 | /Logged in to .* as\s+([^\s(]+)/iu, |
| 52 | 61 | /Logged in to .* account\s+([^\s(]+)/iu, |
| 53 | 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 | 66 | if (account) { |
| 58 | − return SourceControlProviderDiscovery.providerAuth({ status: "authenticated", account, host }); | |
| 67 | + return providerAuth({ status: "authenticated", account, host }); | |
| 59 | 68 | } |
| 60 | 69 | |
| 61 | 70 | if (input.exitCode !== 0) { |
| 62 | − return SourceControlProviderDiscovery.providerAuth({ | |
| 71 | + return providerAuth({ | |
| 63 | 72 | status: "unauthenticated", |
| 64 | 73 | host, |
| 65 | − detail: | |
| 66 | − SourceControlProviderDiscovery.firstSafeAuthLine(output) ?? | |
| 67 | − "Run `glab auth login` to authenticate GitLab CLI.", | |
| 74 | + detail: firstSafeAuthLine(output) ?? "Run `glab auth login` to authenticate GitLab CLI.", | |
| 68 | 75 | }); |
| 69 | 76 | } |
| 70 | 77 | |
| 71 | − return SourceControlProviderDiscovery.providerAuth({ | |
| 78 | + return providerAuth({ | |
| 72 | 79 | status: "unknown", |
| 73 | 80 | host, |
| 74 | − detail: | |
| 75 | − SourceControlProviderDiscovery.firstSafeAuthLine(output) ?? | |
| 76 | − "GitLab CLI auth status could not be parsed.", | |
| 81 | + detail: firstSafeAuthLine(output) ?? "GitLab CLI auth status could not be parsed.", | |
| 77 | 82 | }); |
| 78 | 83 | } |
| 79 | 84 | |
| 80 | −function refineUnknownGitLabRemote( | |
| 81 | − input: SourceControlProviderDiscovery.SourceControlUnknownRemoteRefinementInput, | |
| 82 | −) { | |
| 85 | +function refineUnknownGitLabRemote(input: SourceControlUnknownRemoteRefinementInput) { | |
| 83 | 86 | 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 | + const authenticated = parseGitLabAuthStatusHosts(combinedAuthOutput(input.auth)).some( | |
| 88 | + (entry) => entry.account !== null && entry.host === host, | |
| 89 | + ); | |
| 87 | 90 | |
| 88 | 91 | if (!authenticated) { |
| 89 | 92 | return null; |
| @@ -107,9 +110,9 @@ export const discovery = { · 17 unmodified lines | ||
| 107 | 110 | refineUnknownRemote: refineUnknownGitLabRemote, |
| 108 | 111 | installHint: |
| 109 | 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 | 116 | const gitlab = yield* GitLabCli.GitLabCli; |
| 114 | 117 | |
| 115 | 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); | |