-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
50 lines (40 loc) · 1.09 KB
/
api.js
File metadata and controls
50 lines (40 loc) · 1.09 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
const MAX_PER_PAGE = 100;
const fetchAllPages = async (
request,
params,
maxCount = Number.POSITIVE_INFINITY
) => {
let [page, len, count] = [1, 0, 0];
const result = [];
do {
const { data } = await request({ ...params, per_page: MAX_PER_PAGE, page });
result.push(...data);
[page, len, count] = [page + 1, data.length, count + data.length];
} while (len === MAX_PER_PAGE && count < maxCount);
return result.slice(0, maxCount);
};
export const getPRList = async () => {
return fetchAllPages(global.octokit.rest.pulls.list, {
owner: global.owner,
repo: global.repo,
state: "open",
});
};
export const removeLabel = async (number, name) => {
const { data: labels } = await global.octokit.rest.issues.removeLabel({
owner: global.owner,
repo: global.repo,
issue_number: number,
name,
});
return labels;
};
export const addLabels = async (number, names) => {
const { data: labels } = await global.octokit.rest.issues.addLabels({
owner: global.owner,
repo: global.repo,
issue_number: number,
labels: names,
});
return labels;
};