-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (48 loc) · 1.52 KB
/
index.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
async function main() {
const core = require('@actions/core');
const github = require('@actions/github');
const ghToken = core.getInput('githubToken', {required: true});
const octokit = github.getOctokit(ghToken);
const projectOwnerType = core.getInput('ownerType', {required: true});
const projectOwnerName = core.getInput('ownerName', {required: true});
const projectNumber = parseInt(core.getInput('projectNumber', {required: true}));
const repositoryName = core.getInput('repositoryName', {required: true});
const issueId = parseInt(core.getInput('issueId', {required: true}));
const idResp = await octokit.graphql(
`query getProject($projectOwnerName: String!, $projectNumber: Int!) {
${projectOwnerType}(login: $projectOwnerName) {
projectV2(number: $projectNumber) {
id
}
}
}`,
{
projectOwnerName,
projectNumber
}
)
const projectId = idResp[projectOwnerType]?.projectV2.id
const issue = await octokit.request('GET /repos/{owner}/{repo}/issues/{issue_number}', {
owner: projectOwnerName,
repo: repositoryName,
issue_number: issueId
});
const contentId = issue.data.node_id;
const addResp = await octokit.graphql(
`mutation addIssueToProject($input: AddProjectV2ItemByIdInput!) {
addProjectV2ItemById(input: $input) {
item {
id
}
}
}`,
{
input: {
projectId,
contentId
}
}
)
core.setOutput('itemId', addResp.addProjectV2ItemById.item.id)
}
main()