blob: c1d9300704ef80a783b34f536d7379fe6723ff56 (
plain) (
blame)
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
|
import api from './api.js';
import {getConversationNumber} from './index.js';
export type PullRequestInfo = {
baseRefOid: string;
headRefOid: string;
// https://docs.github.com/en/graphql/reference/enums#mergeablestate
mergeable: 'CONFLICTING' | 'MERGEABLE' | 'UNKNOWN';
viewerCanEditFiles: boolean;
needsUpdate: boolean;
behindBy: number;
};
export default async function getPrInfo(base: string, number = getConversationNumber()!): Promise<PullRequestInfo> {
const {repository} = await api.v4uncached(`
repository() {
pullRequest(number: ${number}) {
baseRefOid
headRefOid
mergeable
viewerCanEditFiles
headRef {
compare(headRef: "${base}") {
status
aheadBy
}
}
}
}
`);
const {
baseRefOid,
headRefOid,
mergeable,
viewerCanEditFiles,
headRef,
} = repository.pullRequest;
return {
baseRefOid,
headRefOid,
mergeable,
viewerCanEditFiles,
// The comparison in the API is base -> head, so it must be flipped
behindBy: headRef.compare.aheadBy,
needsUpdate: headRef.compare.status === 'DIVERGED',
};
}
|