MCPcopy Create free account
hub / github.com/pingdotgg/t3code / parsePullRequestReference

Function parsePullRequestReference

apps/web/src/pullRequestReference.ts:25–59  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

23}
24
25export function parsePullRequestReference(input: string): string | null {
26 const trimmed = input.trim();
27 if (trimmed.length === 0) {
28 return null;
29 }
30
31 const ghCliCheckoutMatch = GITHUB_CLI_PR_CHECKOUT_PATTERN.exec(trimmed);
32 const glabCliCheckoutMatch = GITLAB_CLI_MR_CHECKOUT_PATTERN.exec(trimmed);
33 const azureDevOpsCliCheckoutMatch = AZURE_DEVOPS_CLI_PR_CHECKOUT_PATTERN.exec(trimmed);
34 const normalizedInput =
35 ghCliCheckoutMatch?.[1]?.trim() ??
36 glabCliCheckoutMatch?.[1]?.trim() ??
37 (azureDevOpsCliCheckoutMatch?.[1]
38 ? parseAzureDevOpsCheckoutReference(azureDevOpsCliCheckoutMatch[1])
39 : null) ??
40 trimmed;
41 if (normalizedInput.length === 0) {
42 return null;
43 }
44
45 const urlMatch =
46 GITHUB_PULL_REQUEST_URL_PATTERN.exec(normalizedInput) ??
47 GITLAB_MERGE_REQUEST_URL_PATTERN.exec(normalizedInput) ??
48 AZURE_DEVOPS_PULL_REQUEST_URL_PATTERN.exec(normalizedInput);
49 if (urlMatch?.[1]) {
50 return normalizedInput;
51 }
52
53 const numberMatch = PULL_REQUEST_NUMBER_PATTERN.exec(normalizedInput);
54 if (numberMatch?.[1]) {
55 return numberMatch[1];
56 }
57
58 return null;
59}

Callers 3

PullRequestThreadDialogFunction · 0.90

Calls 1

Tested by

no test coverage detected