refactor(server): resolve title links through source control providers (#11844)
This commit is contained in:
1 parent
8b9f6d3d55
commit
08abda9dcf
17 files changed
+414
-113
No files matched your search
@@ -40,6 +40,8 @@ function makeRegistry(input: {
|
||||
readonly url: string;
|
||||
}>;
|
||||
readonly process?: Partial<VcsProcess.VcsProcess["Service"]>;
|
||||
readonly github?: Partial<GitHubCli.GitHubCli["Service"]>;
|
||||
readonly gitlab?: Partial<GitLabCli.GitLabCli["Service"]>;
|
||||
readonly resolve?: VcsDriverRegistry.VcsDriverRegistry["Service"]["resolve"];
|
||||
}) {
|
||||
const driver = {
|
||||
@@ -92,8 +94,8 @@ function makeRegistry(input: {
|
||||
processLayer,
|
||||
Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({}),
|
||||
Layer.mock(BitbucketApi.BitbucketApi)({}),
|
||||
Layer.mock(GitHubCli.GitHubCli)({}),
|
||||
Layer.mock(GitLabCli.GitLabCli)({}),
|
||||
Layer.mock(GitHubCli.GitHubCli)(input.github ?? {}),
|
||||
Layer.mock(GitLabCli.GitLabCli)(input.gitlab ?? {}),
|
||||
Layer.mock(ForgejoCli.ForgejoCli)({ listLogins: () => Effect.succeed([]) }),
|
||||
ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-source-control-registry-test-",
|
||||
@@ -296,3 +298,50 @@ it.effect("falls back to a non-origin remote when origin is not configured", ()
|
||||
assert.strictEqual(provider.kind, "azure-devops");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"routes linked subjects by URL independently of the checkout and skips unsupported links",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const registry = yield* makeRegistry({
|
||||
remotes: [{ name: "origin", url: "https://github.com/unrelated/checkout.git" }],
|
||||
github: {
|
||||
execute: () =>
|
||||
Effect.succeed(processOutput(JSON.stringify({ title: "GitHub issue", body: null }))),
|
||||
},
|
||||
gitlab: {
|
||||
execute: () =>
|
||||
Effect.succeed(
|
||||
processOutput(JSON.stringify({ title: "GitLab MR", description: "Nested project" })),
|
||||
),
|
||||
},
|
||||
});
|
||||
for (const [url, expected] of [
|
||||
["https://github.com/team/project/issues/1", { title: "GitHub issue", body: null }],
|
||||
[
|
||||
"https://gitlab.com/team/sub/project/-/merge_requests/2",
|
||||
{ title: "GitLab MR", body: "Nested project" },
|
||||
],
|
||||
] as const) {
|
||||
const lookup = registry.resolveLink({ cwd: "/unrelated", url: new URL(url) });
|
||||
assert.ok(lookup);
|
||||
assert.deepStrictEqual(yield* lookup, expected);
|
||||
}
|
||||
for (const url of [
|
||||
"https://example.test/team/project/issues/1",
|
||||
"https://github.attacker.test/team/project/issues/1",
|
||||
"https://gitlab.attacker.test/team/project/-/issues/1",
|
||||
"https://github.com/team/project",
|
||||
"https://codeberg.org/team/project/issues/1",
|
||||
"https://bitbucket.org/team/project/pull-requests/1",
|
||||
"https://dev.azure.com/org/project/_git/repo/pullrequest/1",
|
||||
"http://github.com/team/project/issues/1",
|
||||
"https://user:[email protected]/team/project/issues/1",
|
||||
]) {
|
||||
assert.strictEqual(
|
||||
registry.resolveLink({ cwd: "/unrelated", url: new URL(url) }),
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
}).pipe(Effect.scoped),
|
||||
);
|
||||
Reference in new issue
Block a user