forked from wustep/github-project-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
50 lines (42 loc) · 1.24 KB
/
github.js
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 axios = require("axios");
const API_URL = "https://api.github.com";
class GitHubQuery {
constructor({ owner, repo, token, isOwnerUser }) {
this.owner = owner;
this.repo = repo;
this.token = token;
this.isOwnerUser = isOwnerUser;
}
get = async (url, { prependAPIURL = true } = {}) => {
return (
await axios.get(prependAPIURL ? `${API_URL}/${url}` : url, {
headers: {
Accept: "application/vnd.github.inertia-preview+json",
Authorization: `token ${this.token}`,
},
})
).data;
};
getProjects = async () => {
return await this.get(
this.repo.length
? `repos/${this.owner}/${this.repo}/projects`
: `${this.isOwnerUser ? "users" : "orgs"}/${this.owner}/projects`
);
};
getProjectColumns = async (projectId) => {
return await this.get(`projects/${projectId}/columns`);
};
getColumnCards = async (columnId) => {
let result = [];
let page = 1;
let limit = 100;
do {
const res = await this.get(`projects/columns/${columnId}/cards?per_page=${limit}&page=${page}`);
result = [...result, ...res]
page++;
} while (result.length >= limit * (page - 1));
return result;
};
}
module.exports = { GitHubQuery };