-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
61 lines (56 loc) · 1.44 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
51
52
53
54
55
56
57
58
59
60
61
const github = require("@actions/github");
function createGitHubClient(token, repo) {
const octokit = github.getOctokit(token);
return {
async getRepoData() {
const repoName = repo.substr(repo.indexOf("/") + 1);
const {
data: { node_id: repoId },
} = await octokit.repos.get({
owner: "BrownUniversity",
repo: repoName,
});
const issues = await octokit.paginate(
"GET /repos/{owner}/{repo}/issues",
{
owner: "BrownUniversity",
repo: repoName,
}
);
return {
repoId,
issues,
};
},
async createIssue({ repoId, title }) {
const data = await octokit.graphql(
`mutation CreateIssue($repoId: ID!, $title: String!) {
createIssue(input: { repositoryId: $repoId, title: $title }) {
issue {
number
}
}
}`,
{ repoId, title }
);
return data.createIssue.issue.number;
},
async updateIssueTitle(issueId, title) {
const data = await octokit.graphql(
`mutation UpdateIssueTitle($issueId: ID!, $title: String!) {
updateIssue(input: { id: $issueId, title: $title }) {
issue {
number
title
}
}
}`,
{ issueId, title }
);
return data.updateIssue.issue.number;
},
};
}
module.exports = {
createGitHubClient,
};