-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (55 loc) · 2.26 KB
/
Copy pathindex.js
File metadata and controls
67 lines (55 loc) · 2.26 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
const core = require("@actions/core");
const { context, getOctokit } = require("@actions/github");
async function run() {
try {
const githubToken = core.getInput('github_token');
let labelsByOrganizationInput = core.getInput('labels_by_organization');
if (!labelsByOrganizationInput) {
core.setFailed("At least the labels_by_organization parameter must be set!");
return;
}
const labelsByOrganization = new Map(Object.entries(JSON.parse(labelsByOrganizationInput)))
const [owner, repo] = core.getInput('repository').split('/');
const issueNumber =
core.getInput('issue_number') === ''
? context.issue.number
: parseInt(core.getInput('issue_number'));
const target = context.payload.pull_request || context.payload.issue
const author = target.user.login
console.log(`author : ${author}`);
if (!issueNumber) {
core.setFailed("Cannot infer the target issue parameter!");
return;
}
const client = getOctokit(githubToken);
const remainingAdd = [];
labelsByOrganization.forEach(async (value, key) => {
await client.rest.orgs.listMembers({org: key}).then((listMembers) => {
listMembers.data.forEach(async (member) => {
if (member.login === author) {
for (const label of value) {
try {
await client.rest.issues.addLabels({
labels: [label],
owner,
repo,
issue_number: issueNumber
});
} catch (e) {
core.warning(`failed to add label: ${label}: ${e}`);
remainingAdd.push(label);
}
}
}
})
});
});
if (remainingAdd.length) {
throw new Error(`failed to add labels: ${remainingAdd}`);
}
} catch (e) {
core.error(e);
}
}
run();