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