forked from vj-abigo/invite-on-label
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (51 loc) · 1.79 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
55
56
57
58
const core = require('@actions/core');
const github = require('@actions/github');
const main = async () => {
try {
const { INVITE_TOKEN } = process.env;
const repoToken = core.getInput('repo-token', { required: true });
if (!INVITE_TOKEN) {
return core.setFailed('ENV required and not supplied: INVITE_TOKEN');
}
const octokit = github.getOctokit(INVITE_TOKEN);
const client = github.getOctokit(repoToken);
const { payload } = github.context;
const inviteeId = payload.issue.user.id;
// const currentLabel = payload.label.name;
const org = core.getInput('organization', { required: true });
// const label = core.getInput('label', { required: true });
const comment = core.getInput('comment');
// if (currentLabel === label) { //改成无条件邀请
try {
await octokit.orgs.checkMembership({
org,
username: payload.issue.user.login,
});
} catch (error) {
await octokit.orgs.createInvitation({
org,
invitee_id: inviteeId,
});
core.info('Invitation sent successfully 🎉🎉');
core.info('Adding a comment before closing the issue');
await client.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: comment,
});
core.info('Closing the issue');
await client.issues.update({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
state: 'closed',
});
}
// }
} catch (error) {
return core.setFailed(error.message);
}
return core.setOutput('Invitation sent successfully 🎉🎉');
};
main();