(absolute: string, relative: string)
| 29 | @example parseReferenceRaw('fregante/mem:main', 'main') |
| 30 | */ |
| 31 | export 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 | |
| 55 | function parseReference(referenceElement: HTMLElement): PrReference { |
| 56 | const {title, textContent, nextElementSibling} = referenceElement; |
no test coverage detected