| 1 | /** |
| 2 | * GitLab's client definition. Browser- and React Native-safe. |
| 3 | * |
| 4 | * @module source-control-gitlab/client/definition |
| 5 | */ |
| 6 | import { SourceControlProviderKind } from "@t3tools/contracts"; |
| 7 | import { |
| 8 | defineSourceControlClient, |
| 9 | isChangeRequestInProjectRepository, |
| 10 | isChangeRequestOnProjectHost, |
| 11 | isChangeRequestPath, |
| 12 | } from "@t3tools/source-control-core/client/definition"; |
| 13 | |
| 14 | const CHECKOUT_COMMAND = /^glab\s+mr\s+checkout\s+(.+)$/i; |
| 15 | const CHANGE_REQUEST_REFERENCE = |
| 16 | /^https:\/\/[^/\s]*gitlab[^/\s]*\/.+\/-\/merge_requests\/(\d+)(?:[/?#].*)?$/i; |
| 17 | |
| 18 | const KIND = SourceControlProviderKind.make("gitlab"); |
| 19 | |
| 20 | export const definition = defineSourceControlClient({ |
| 21 | kind: KIND, |
| 22 | label: "GitLab", |
| 23 | pickerLabel: "GitLab", |
| 24 | icon: "gitlab", |
| 25 | changeRequest: { shortLabel: "MR", singular: "merge request" }, |
| 26 | repositoryPathHint: "group/project", |
| 27 | publicHost: "gitlab.com", |
| 28 | publishDescription: "gitlab.com", |
| 29 | publishHost: () => "gitlab.com", |
| 30 | newRepositoryOwner: (account) => ({ owner: account }), |
| 31 | defaultCloneTransport: "ssh", |
| 32 | changeRequestUrl: ({ host, repository, number }) => |
| 33 | `https://${host}/${repository}/-/merge_requests/${number}`, |
| 34 | changeRequestActions: new Set([ |
| 35 | "merge", |
| 36 | "ready", |
| 37 | "draft", |
| 38 | "close", |
| 39 | "reopen", |
| 40 | "update-branch", |
| 41 | "enable-auto-merge", |
| 42 | "disable-auto-merge", |
| 43 | ] as const), |
| 44 | checkoutCommand: ({ number }) => `glab mr checkout ${number}`, |
| 45 | authorProfileUrl: () => null, |
| 46 | referenceAutolinkRepositoryUrl: () => null, |
| 47 | reviewSummaryRequired: () => false, |
| 48 | checkoutCommandArgument: (input) => CHECKOUT_COMMAND.exec(input)?.[1]?.trim() ?? null, |
| 49 | isChangeRequestReference: (url) => CHANGE_REQUEST_REFERENCE.test(url), |
| 50 | changeRequestUrlHost: (url) => url.hostname, |
| 51 | checkoutChangeRequestHost: () => null, |
| 52 | isChangeRequestInRepository: (identity, link) => |
| 53 | isChangeRequestInProjectRepository(KIND, identity, link), |
| 54 | canReadChangeRequestOnHost: (identity, link) => |
| 55 | isChangeRequestOnProjectHost(KIND, identity, link), |
| 56 | isChangeRequestUrl: (url) => isChangeRequestPath(url, "/-/merge_requests/"), |
| 57 | }); |