forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-branches.ts
More file actions
34 lines (27 loc) · 936 Bytes
/
pr-branches.ts
File metadata and controls
34 lines (27 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import select from 'select-dom';
import splitOnFirst from 'split-on-first';
export type PrReference = {
/** @example fregante/mem:main */
full: string;
/** @example "main" on same-repo PRs, "fregante:main" on cross-repo PRs */
local: string;
/** @example fregante */
owner: string;
/** @example mem */
name: string;
/** @example main */
branch: string;
};
function parseReference(referenceElement: HTMLElement): PrReference {
const {title: full, textContent: local} = referenceElement;
const [nameWithOwner, branch] = splitOnFirst(full, ':') as [string, string];
const [owner, name] = nameWithOwner.split(':');
return {full, owner, name, branch, local: local!.trim()};
}
// TODO: Use in more places, like anywhere '.base-ref' appears
export function getBranches(): {base: PrReference; head: PrReference} {
return {
base: parseReference(select('.base-ref')!),
head: parseReference(select('.head-ref')!),
};
}