MCPcopy
hub / github.com/refined-github/refined-github / parseReferenceRaw

Function parseReferenceRaw

source/github-helpers/pr-branches.ts:31–53  ·  view source on GitHub ↗
(absolute: string, relative: string)

Source from the content-addressed store, hash-verified

29@example parseReferenceRaw('fregante/mem:main', 'main')
30*/
31export function parseReferenceRaw(absolute: string, relative: string): PrReference {
32 const absoluteMatch = absoluteReferenceRegex.exec(absolute);
33 if (!absoluteMatch) {
34 throw new TypeError(`Expected \`absolute\` to be "user/repo:branch", got "${absolute}"`);
35 }
36
37 const {owner, name, nameWithOwner, branch} = absoluteMatch.groups!;
38
39 // We must receive the relative reference because it also tells whether it's a cross-repo PR
40 const expectedRelative = [branch, `${owner}:${branch}`];
41 if (!expectedRelative.includes(relative)) {
42 throw new TypeError(`Expected \`relative\` to be either "${expectedRelative.join('" or "')}", got "${relative}"`);
43 }
44
45 return {
46 owner,
47 name,
48 branch,
49 nameWithOwner,
50 absolute,
51 relative,
52 };
53}
54
55function parseReference(referenceElement: HTMLElement): PrReference {
56 const {title, textContent, nextElementSibling} = referenceElement;

Callers 3

parseReferenceFunction · 0.85
cleanPrHeaderFunction · 0.85

Calls 1

includesMethod · 0.80

Tested by

no test coverage detected