forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-pr-info.ts
More file actions
55 lines (47 loc) · 1.3 KB
/
get-pr-info.ts
File metadata and controls
55 lines (47 loc) · 1.3 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as pageDetect from 'github-url-detection';
import * as api from './api';
import {getConversationNumber} from '.';
type PullRequestInfo = {
// TODO: Use this for `restore-file` when GHE supports `compare`
baseRefOid: string;
// https://docs.github.com/en/graphql/reference/enums#mergeablestate
mergeable: 'CONFLICTING' | 'MERGEABLE' | 'UNKNOWN';
viewerCanEditFiles: boolean;
};
export default async function getPrInfo(base: string, head: string, number = getConversationNumber()!): Promise<PullRequestInfo | undefined> {
if (pageDetect.isEnterprise()) {
const {repository} = await api.v4(`
repository() {
pullRequest(number: ${number}) {
mergeable
viewerCanEditFiles
}
}
`);
const compare = await api.v3(`compare/${base}...${head}?page=10000`); // `page=10000` avoids fetching any commit information, which is heavy
if (compare.status !== 'diverged') {
return;
}
return repository.pullRequest;
}
const {repository} = await api.v4(`
repository() {
pullRequest(number: ${number}) {
baseRefOid
mergeable
viewerCanEditFiles
headRef {
compare(headRef: "${base}") {
status
behindBy
aheadBy
}
}
}
}
`);
if (repository.pullRequest.headRef.compare.status !== 'DIVERGED') {
return;
}
return repository.pullRequest;
}