refactor(server): resolve title links through source control providers (#11844)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-14 19:57:34 -07:00
1 parent 8b9f6d3d55
commit 08abda9dcf
17 files changed
+414 -113

No files matched your search

@@ -1,3 +1,4 @@
import * as Schema from "effect/Schema";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
@@ -20,6 +21,12 @@ import {
type SourceControlCliDiscoverySpec,
} from "./SourceControlProviderDiscovery.ts";
const decodeLinkSubject = Schema.decodeUnknownEffect(
Schema.fromJsonString(
Schema.Struct({ title: Schema.String, body: Schema.NullOr(Schema.String) }),
),
);
function toChangeRequest(summary: GitHubCli.GitHubPullRequestSummary): ChangeRequest {
return {
provider: "github",
@@ -208,8 +215,45 @@ export const make = Effect.gen(function* () {
);
};
const readLinkSubject = Effect.fn("GitHubSourceControlProvider.readLinkSubject")(function* (
input: { readonly cwd: string; readonly url: URL },
endpoint: string,
) {
return yield* github
.execute({
cwd: input.cwd,
args: ["api", "--hostname", input.url.host, endpoint, "--jq", "{title, body}"],
env: { GH_PROMPT_DISABLED: "1" },
timeoutMs: 3_000,
maxOutputBytes: 32_000,
})
.pipe(
Effect.flatMap((result) => decodeLinkSubject(result.stdout)),
Effect.map((subject) => ({ title: subject.title, body: subject.body })),
Effect.mapError(
(cause) =>
new SourceControlProviderError({
provider: "github",
operation: "resolveLink",
cwd: input.cwd,
detail: "The linked subject could not be read.",
cause,
}),
),
);
});
return SourceControlProvider.SourceControlProvider.of({
kind: "github",
resolveLink: (input) => {
// Automatic enrichment must not send ambient CLI credentials to a host from message text.
if (input.url.host !== "github.com") return undefined;
const match = /^\/([\w.-]+)\/([\w.-]+)\/(?:pull|issues)\/([1-9]\d*)(?:\/.*)?$/.exec(
input.url.pathname,
);
if (!match) return undefined;
return readLinkSubject(input, `repos/${match[1]}/${match[2]}/issues/${match[3]}`);
},
listChangeRequests,
getChangeRequest: (input) =>
github.getPullRequest(input).pipe(