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

definition.ts

93 lines3.2 KB

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 changeRequestUrlBelow,
11 defineSourceControl,
12 isChangeRequestInProjectRepository,
13 isChangeRequestOnProjectHost,
14 parseChangeRequestPath,
15 projectChangeRequestHost,
16} from "@t3tools/source-control-core/shared/definition";
17import { icon } from "./icon.ts";
18​
19/** GitCafe has no self-hosted installs: production and staging are its only hosts. */
20const GITCAFE_HOSTS = new Set(["git.cafe", "staging.git.cafe"]);
21​
22/** GitCafe serves pull requests at `/pull/<n>` and redirects the older `/pulls/<n>` there. */
23const CHANGE_REQUEST_PATH = /^\/([^/]+\/[^/]+)\/pulls?\/(\d+)(?:\/|$)/u;
24​
25const KIND = SourceControlProviderKind.make("gitcafe");
26​
27export const settings = makeProviderSettingsSchema({
28 token: TrimmedString.pipe(
29 secretSetting,
30 Schema.withDecodingDefault(Effect.succeed("")),
31 Schema.annotateKey({
32 title: "Token",
33 description:
34 "A git.cafe token, used before CAFE_TOKEN and the cafe login, so GitCafe works without the CLI signed in.",
35 providerSettingsForm: { control: "password" },
36 }),
37 ),
38});
39export type GitCafeSettings = typeof settings.Type;
40​
41export const definition = defineSourceControl({
42 kind: KIND,
43 label: "GitCafe",
44 pickerLabel: "GitCafe",
45 icon,
46 changeRequest: {
47 shortLabel: "PR",
48 shortLabelWithArticle: "a PR",
49 singular: "pull request",
50 plural: "pull requests",
51 },
52 repositoryPathHint: "owner/repo",
53 publicHost: "git.cafe",
54 publishDescription: "git.cafe",
55 publishHost: () => "git.cafe",
56 newRepositoryOwner: (account) => (account ? { owner: account } : null),
57 defaultCloneTransport: "ssh",
58 changeRequestUrl: ({ host, repository, number, webUrl }) =>
59 webUrl
60 ? changeRequestUrlBelow(webUrl, `pulls/${number}`)
61 : `https://${host}/${repository}/pulls/${number}`,
62 // `/pull/` and `/pulls/` are GitHub's and Forgejo's shapes too, so only GitCafe's own hosts
63 // claim them.
64 parseChangeRequestUrl: (url) =>
65 GITCAFE_HOSTS.has(url.hostname.toLowerCase())
66 ? parseChangeRequestPath(url, CHANGE_REQUEST_PATH)
67 : null,
68 changeRequestUrlFromReferenceAutolink: () => null,
69 changeRequestActions: new Set([
70 "ready",
71 "draft",
72 "close",
73 "reopen",
74 "merge",
75 "update-branch",
76 ] as const),
77 checkoutCommand: ({ number }) => `cafe pr checkout ${number}`,
78 changeRequestCloseCommand: /\bcafe\s+(?:pr|stack)\s+(?:merge|close)\b/u,
79 authorProfileUrl: () => null,
80 reviewSummaryRequired: () => false,
81 checkoutCommandArgument: () => null,
82 isChangeRequestReference: () => false,
83 checkoutChangeRequestHost: () => null,
84 recognizeRemote: ({ hostname }) =>
85 GITCAFE_HOSTS.has(hostname)
86 ? { kind: KIND, name: "GitCafe", baseUrl: `https://${hostname}` }
87 : null,
88 isChangeRequestInRepository: (identity, link) =>
89 isChangeRequestInProjectRepository(projectChangeRequestHost(identity, KIND), identity, link),
90 canReadChangeRequestOnHost: (identity, link) =>
91 isChangeRequestOnProjectHost(projectChangeRequestHost(identity, KIND), identity, link),
92 settings,
93});