refactor(source-control): reference parsing and project matching are host resolvers (#17770)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5.5 authored and GitHub committed 2026-10-10 12:07:01 -07:00
1 parent 579159d6c6
commit b0249ac871
10 files changed
+286 -136

No files matched your search

@@ -3,14 +3,22 @@
*
* @module source-control-github/client/definition
*/
import { SourceControlProviderKind } from "@t3tools/contracts";
import { pullRequestHostOf, SourceControlProviderKind } from "@t3tools/contracts";
import {
defineSourceControlClient,
isChangeRequestInProjectRepository,
isChangeRequestOnProjectHost,
isChangeRequestPath,
} from "@t3tools/source-control-core/client/definition";
const CHECKOUT_COMMAND = /^gh\s+pr\s+checkout\s+(.+)$/i;
const CHANGE_REQUEST_REFERENCE =
/^https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/(\d+)(?:[/?#].*)?$/i;
const KIND = SourceControlProviderKind.make("github");
export const definition = defineSourceControlClient({
kind: SourceControlProviderKind.make("github"),
kind: KIND,
label: "GitHub",
pickerLabel: "GitHub",
icon: "github",
@@ -29,5 +37,14 @@ export const definition = defineSourceControlClient({
: new URL(`/${encodeURIComponent(login)}`, repositoryUrl).toString(),
referenceAutolinkRepositoryUrl: (repositoryUrl) => repositoryUrl,
reviewSummaryRequired: () => false,
checkoutCommandArgument: (input) => CHECKOUT_COMMAND.exec(input)?.[1]?.trim() ?? null,
isChangeRequestReference: (url) => CHANGE_REQUEST_REFERENCE.test(url),
changeRequestUrlHost: (url) => url.hostname,
// A GitHub web host is the checkout's own host, Enterprise installs included.
checkoutChangeRequestHost: (identity) => pullRequestHostOf(identity, KIND),
isChangeRequestInRepository: (identity, link) =>
isChangeRequestInProjectRepository(KIND, identity, link),
canReadChangeRequestOnHost: (identity, link) =>
isChangeRequestOnProjectHost(KIND, identity, link),
isChangeRequestUrl: (url) => isChangeRequestPath(url, "/pull/"),
});