[codex] Migrate server source control Effect services (#3186)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
7118e43d16
commit
d9e9539862
42 files changed
+1326
-1328
No files matched your search
@@ -11,9 +11,15 @@ import {
|
||||
|
||||
import * as GitHubCli from "./GitHubCli.ts";
|
||||
import { findAuthenticatedGitHubAccount, parseGitHubAuthStatus } from "./gitHubAuthStatus.ts";
|
||||
import * as GitHubPullRequests from "./gitHubPullRequests.ts";
|
||||
import { decodeGitHubPullRequestListJson } from "./gitHubPullRequests.ts";
|
||||
import * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderDiscovery from "./SourceControlProviderDiscovery.ts";
|
||||
import {
|
||||
combinedAuthOutput,
|
||||
firstSafeAuthLine,
|
||||
providerAuth,
|
||||
type SourceControlAuthProbeInput,
|
||||
type SourceControlCliDiscoverySpec,
|
||||
} from "./SourceControlProviderDiscovery.ts";
|
||||
const isSourceControlProviderError = Schema.is(SourceControlProviderError);
|
||||
|
||||
function providerError(
|
||||
@@ -50,14 +56,14 @@ function toChangeRequest(summary: GitHubCli.GitHubPullRequestSummary): ChangeReq
|
||||
};
|
||||
}
|
||||
|
||||
function parseGitHubAuth(input: SourceControlProviderDiscovery.SourceControlAuthProbeInput) {
|
||||
const output = SourceControlProviderDiscovery.combinedAuthOutput(input);
|
||||
function parseGitHubAuth(input: SourceControlAuthProbeInput) {
|
||||
const output = combinedAuthOutput(input);
|
||||
const authStatus = parseGitHubAuthStatus(input.stdout);
|
||||
const authenticatedAccount = findAuthenticatedGitHubAccount(authStatus.accounts);
|
||||
const host = authenticatedAccount?.host;
|
||||
|
||||
if (authenticatedAccount) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "authenticated",
|
||||
account: authenticatedAccount.account,
|
||||
host,
|
||||
@@ -66,7 +72,7 @@ function parseGitHubAuth(input: SourceControlProviderDiscovery.SourceControlAuth
|
||||
|
||||
const failedAccount = authStatus.accounts.find((entry) => entry.active) ?? authStatus.accounts[0];
|
||||
if (authStatus.parsed) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unauthenticated",
|
||||
host: failedAccount?.host,
|
||||
detail:
|
||||
@@ -76,21 +82,17 @@ function parseGitHubAuth(input: SourceControlProviderDiscovery.SourceControlAuth
|
||||
}
|
||||
|
||||
if (input.exitCode !== 0) {
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unauthenticated",
|
||||
host,
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(output) ??
|
||||
"Run `gh auth login` to authenticate GitHub CLI.",
|
||||
detail: firstSafeAuthLine(output) ?? "Run `gh auth login` to authenticate GitHub CLI.",
|
||||
});
|
||||
}
|
||||
|
||||
return SourceControlProviderDiscovery.providerAuth({
|
||||
return providerAuth({
|
||||
status: "unknown",
|
||||
host,
|
||||
detail:
|
||||
SourceControlProviderDiscovery.firstSafeAuthLine(output) ??
|
||||
"GitHub CLI auth status could not be parsed.",
|
||||
detail: firstSafeAuthLine(output) ?? "GitHub CLI auth status could not be parsed.",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,12 +106,12 @@ export const discovery = {
|
||||
parseAuth: parseGitHubAuth,
|
||||
installHint:
|
||||
"Install the GitHub command-line tool (`gh`) via https://cli.github.com/ or your package manager (for example `brew install gh`).",
|
||||
} satisfies SourceControlProviderDiscovery.SourceControlCliDiscoverySpec;
|
||||
} satisfies SourceControlCliDiscoverySpec;
|
||||
|
||||
export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
|
||||
export const make = Effect.gen(function* () {
|
||||
const github = yield* GitHubCli.GitHubCli;
|
||||
|
||||
const listChangeRequests: SourceControlProvider.SourceControlProviderShape["listChangeRequests"] =
|
||||
const listChangeRequests: SourceControlProvider.SourceControlProvider["Service"]["listChangeRequests"] =
|
||||
(input) => {
|
||||
if (input.state === "open") {
|
||||
return github
|
||||
@@ -147,7 +149,7 @@ export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
|
||||
if (raw.length === 0) {
|
||||
return Effect.succeed([]);
|
||||
}
|
||||
return Effect.sync(() => GitHubPullRequests.decodeGitHubPullRequestListJson(raw)).pipe(
|
||||
return Effect.sync(() => decodeGitHubPullRequestListJson(raw)).pipe(
|
||||
Effect.flatMap((decoded) =>
|
||||
Result.isSuccess(decoded)
|
||||
? Effect.succeed(
|
||||
@@ -212,4 +214,4 @@ export const make = Effect.fn("makeGitHubSourceControlProvider")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make());
|
||||
export const layer = Layer.effect(SourceControlProvider.SourceControlProvider, make);
|
||||
Reference in new issue
Block a user