Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

definition.ts

88 lines3.0 KB

1/**
2 * GitCafe's client definition. Browser- and React Native-safe.
3 *
4 * @module source-control-gitcafe/client/definition
5 */
6import {
7 makeProviderSettingsSchema,
8 SourceControlProviderKind,
9 TrimmedString,
10} from "@t3tools/contracts";
11import * as Effect from "effect/Effect";
12import * as Schema from "effect/Schema";
13import {
14 defineSourceControlClient,
15 isChangeRequestInProjectRepository,
16 isChangeRequestOnProjectHost,
17 isChangeRequestPath,
18} from "@t3tools/source-control-core/client/definition";
19​
20/** GitCafe has no self-hosted installs: production and staging are its only hosts. */
21const GITCAFE_HOSTS = new Set(["git.cafe", "staging.git.cafe"]);
22​
23const KIND = SourceControlProviderKind.make("gitcafe");
24​
25/** A git.cafe token, used before `CAFE_TOKEN` and the `cafe` login. */
26export const settings = makeProviderSettingsSchema({
27 token: TrimmedString.pipe(
28 Schema.withDecodingDefault(Effect.succeed("")),
29 Schema.annotateKey({
30 title: "Token",
31 description:
32 "A git.cafe token, used before CAFE_TOKEN and the cafe login, so GitCafe works without the CLI signed in.",
33 providerSettingsForm: { control: "password", secret: true },
34 }),
35 ),
36});
37export type GitCafeSettings = typeof settings.Type;
38​
39export const definition = defineSourceControlClient({
40 kind: KIND,
41 label: "GitCafe",
42 pickerLabel: "GitCafe",
43 icon: "gitcafe",
44 changeRequest: { shortLabel: "PR", singular: "pull request" },
45 repositoryPathHint: "owner/repo",
46 // Left unattributed so a reference with no repository identity behind it gets no checkout
47 // command guessed from its hostname alone.
48 publicHost: null,
49 publishDescription: "git.cafe",
50 publishHost: () => "git.cafe",
51 newRepositoryOwner: (account) => (account ? { owner: account } : null),
52 defaultCloneTransport: "ssh",
53 changeRequestUrl: ({ host, repository, number }) =>
54 `https://${host}/${repository}/pulls/${number}`,
55 changeRequestActions: new Set([
56 "ready",
57 "draft",
58 "close",
59 "reopen",
60 "merge",
61 "update-branch",
62 ] as const),
63 checkoutCommand: ({ number }) => `cafe pr checkout ${number}`,
64 authorProfileUrl: () => null,
65 referenceAutolinkRepositoryUrl: () => null,
66 reviewSummaryRequired: () => false,
67 // `/pulls/` is Forgejo's shape too, so only GitCafe's own hosts claim it.
68 // `cafe pr checkout` and git.cafe URLs were never accepted in reference fields.
69 checkoutCommandArgument: () => null,
70 isChangeRequestReference: () => false,
71 changeRequestUrlHost: (url) => url.hostname,
72 checkoutChangeRequestHost: () => null,
73 isChangeRequestInRepository: (identity, link) =>
74 isChangeRequestInProjectRepository(KIND, identity, link),
75 canReadChangeRequestOnHost: (identity, link) =>
76 isChangeRequestOnProjectHost(KIND, identity, link),
77 isChangeRequestUrl: (url) => {
78 try {
79 return (
80 GITCAFE_HOSTS.has(new URL(url).hostname.toLowerCase()) &&
81 isChangeRequestPath(url, "/pulls/")
82 );
83 } catch {
84 return false;
85 }
86 },
87 settings,
88});