| 1 | /** |
| 2 | * The source control host definitions web and mobile ship, and the one lookup they use. |
| 3 | * |
| 4 | * Adding a host means writing its `@t3tools/source-control-<host>` package with a |
| 5 | * `./client/definition` entry and adding it here; clients then label, list, and check out its |
| 6 | * change requests without further branches. |
| 7 | * |
| 8 | * @module client-runtime/sourceControlClients |
| 9 | */ |
| 10 | import * as AzureDevOps from "@t3tools/source-control-azure-devops/client/definition"; |
| 11 | import * as Bitbucket from "@t3tools/source-control-bitbucket/client/definition"; |
| 12 | import { |
| 13 | makeSourceControlClientRegistry, |
| 14 | readSourceControlHostSettings, |
| 15 | } from "@t3tools/source-control-core/client/definition"; |
| 16 | import type { ServerSettings } from "@t3tools/contracts"; |
| 17 | |
| 18 | export { |
| 19 | UNKNOWN_SOURCE_CONTROL_CLIENT, |
| 20 | type ChangeRequestTerminology, |
| 21 | type SourceControlClientDefinition, |
| 22 | } from "@t3tools/source-control-core/client/definition"; |
| 23 | import * as Forgejo from "@t3tools/source-control-forgejo/client/definition"; |
| 24 | import * as GitCafe from "@t3tools/source-control-gitcafe/client/definition"; |
| 25 | import * as GitHub from "@t3tools/source-control-github/client/definition"; |
| 26 | import * as GitLab from "@t3tools/source-control-gitlab/client/definition"; |
| 27 | |
| 28 | /** |
| 29 | * GitHub comes first because a repository that has not reported its host yet reads as GitHub, |
| 30 | * which is what clients have always shown there. A change request URL goes to the first host |
| 31 | * whose shape it has, so GitCafe, which claims `/pulls/` only on its own hostnames, comes before |
| 32 | * Forgejo, which claims it everywhere. Pickers sort by readiness and label, not by this order. |
| 33 | */ |
| 34 | const BUILT_IN_SOURCE_CONTROL_CLIENTS = [ |
| 35 | GitHub.definition, |
| 36 | GitLab.definition, |
| 37 | GitCafe.definition, |
| 38 | Forgejo.definition, |
| 39 | Bitbucket.definition, |
| 40 | AzureDevOps.definition, |
| 41 | ]; |
| 42 | |
| 43 | /** `definitions` lists the built-in hosts in that order, for pickers that offer every host. */ |
| 44 | export const sourceControlClients = makeSourceControlClientRegistry( |
| 45 | BUILT_IN_SOURCE_CONTROL_CLIENTS, |
| 46 | ); |
| 47 | |
| 48 | export type { GitHubSettings } from "@t3tools/source-control-github/client/definition"; |
| 49 | |
| 50 | /** |
| 51 | * An environment's GitHub host choices and tokens, decoded with GitHub's settings schema. GitHub's |
| 52 | * settings panels are its own, since its logins come from `gh` at runtime. |
| 53 | */ |
| 54 | export function readGitHubSettings(settings: Pick<ServerSettings, "sourceControlHosts">) { |
| 55 | return readSourceControlHostSettings(GitHub.settings, settings.sourceControlHosts.github); |
| 56 | } |