-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (50 loc) · 1.65 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
/*
* @Descripttion:
* @version:
* @Author: 松岛川树
* @Date: 2021-12-18 20:47:46
* @LastEditors: 松岛川树
* @LastEditTime: 2021-12-18 23:15:51
* @FilePath: \org-invite-bot\index.js
*/
require('dotenv').config()
const { Octokit } = require('@octokit/core')
const {
GH_TOKEN: githubToken,
GITHUB_ORG_NAME: githubOrgName,
} = process.env
const octokit = new Octokit({
auth: githubToken,
});
(
async () => {
//Get an application organization problem
let { data } = await octokit.request('GET /orgs/{org}/issues?filter=all', {
org: githubOrgName,
})
// Filter out the problem tag for the INVITE Me To the Organization problem
let inviteIssues = data.filter(item => item.labels.some(label => label.name === 'invite me to the organisation'))
// send invitation
for (let issue of inviteIssues) {
const { data: { id } } = await octokit.request(`/users/${issue.user.login}`);
const { status } = await octokit.request('POST /orgs/{org}/invitations', {
org: githubOrgName,
invitee_id: id
});
switch (status) {
case 201:
console.info(`Invitation success!${issue.user.login}`)
break;
case 422:
console.error(`Failed!${issue.user.login}`)
break;
case 404:
console.error(`404 Not Found`)
break;
default:
console.error(`Failed!${issue.user.login}`)
break;
}
}
}
)()