-
Notifications
You must be signed in to change notification settings - Fork 1
/
apiwrapper.js
88 lines (79 loc) · 1.98 KB
/
apiwrapper.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class ApiWrapper {
#octokit;
constructor({ octokit }) {
this.#octokit = octokit;
}
async createProject({ title, organization, repository }) {
const { createProjectV2: { projectV2: { id } } } = await this.#octokit.graphql(`
mutation createProject {
createProjectV2(
input: {
ownerId: "${organization.id}",
title: "${title}",
repositoryId: "${repository.id}",
}
){
projectV2 {
id
}
}
}`);
return id;
}
async fetchOrganiztion({ ownerName }) {
const { organization } = await this.#octokit.graphql(
`
query fetchOrgainzation {
organization(login: "${ownerName}") {
id
name
}
}`,
{
headers: {
'X-Github-Next-Global-ID': '1',
},
},
);
return organization;
}
async fetchRepository({ ownerName, repositoryName }) {
// max limit for `first` is 100
// https://docs.github.com/en/graphql/overview/resource-limitations
const response = await this.#octokit.graphql.paginate(`
query paginate($cursor: String) {
repository(owner: "${ownerName}", name: "${repositoryName}") {
name
id
projectsV2(first: 100, after: $cursor) {
nodes {
id
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}`);
return response.repository;
}
async deleteProject({ project, clientMutationId }) {
const { projectId: id } = await this.#octokit.graphql(`
mutation deleteProject {
deleteProjectV2(
input: {
clientMutationId: "${clientMutationId}"
projectId: "${project.id}",
}
){
projectV2 {
id
}
}
}`);
return id;
}
}
export { ApiWrapper }; // eslint-disable-line import/prefer-default-export