Skip to content

Commit 1ade612

Browse files
committed
add
1 parent 6f782ca commit 1ade612

File tree

4 files changed

+108
-12
lines changed

4 files changed

+108
-12
lines changed

.gitignore

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
# @source: https://github.com/xrkffgg/gitignore/blob/master/.gitignore
22

3-
# Normal
4-
.DS_Store
5-
node_modules
3+
# production
64
/dist
7-
.sass-cache/
5+
/docs-dist
6+
7+
# Log file
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Private
14+
.env
15+
16+
# misc
17+
.DS_Store
818

9-
# Lock
19+
# dependencies
20+
node_modules
1021
yarn.lock
1122
package-lock.json
1223

@@ -20,12 +31,6 @@ package-lock.json
2031
*.sass.map
2132
*.scss.map
2233

23-
# Log file
24-
*.log
25-
npm-debug.log*
26-
yarn-debug.log*
27-
yarn-error.log*
28-
2934
# Editor directories and files
3035
.idea
3136
.vscode
@@ -34,4 +39,13 @@ yarn-error.log*
3439
*.njsproj
3540
*.sln
3641
*.sw?
37-
~$*.*
42+
~$*.*
43+
44+
# umi
45+
.umi
46+
.umi-production
47+
.umi-test
48+
.env.local
49+
50+
# cache
51+
.sass-cache/

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dependencies": {
3+
"@actions/core": "^1.2.6",
4+
"@octokit/rest": "^18.0.6",
5+
"axios": "^0.21.0",
6+
"dotenv": "^8.2.0"
7+
}
8+
}

script/auto-invite.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require('dotenv').config();
2+
const core = require('@actions/core')
3+
const { Octokit } = require('@octokit/rest');
4+
const axios = require('axios');
5+
6+
const {
7+
GH_TOKEN: githubToken,
8+
ISSUE_AUTH,
9+
ISSUE_NUMBER,
10+
} = process.env;
11+
const issueAuth = ISSUE_AUTH || 'xrkffgg';
12+
const issueNumber = ISSUE_NUMBER || 48;
13+
14+
const issueBody = `🎉 Hi, @${issueAuth}. Already invited, please check your email.
15+
<!-- Created by GitHub Actios. -->
16+
`;
17+
18+
const octokit = new Octokit({ auth: `token ${githubToken}` });
19+
20+
const owner = 'zoo-js';
21+
const repo = 'zoo';
22+
const url = 'https://raw.githubusercontent.com/zoo-js/zoo-data/main/json/organizations.json';
23+
let organizations = [];
24+
25+
async function main() {
26+
const res = await octokit.issues.listComments({
27+
owner,
28+
repo,
29+
issue_number: issueNumber
30+
});
31+
32+
const targetArr = res.data.pop().body.split('\r\n');
33+
const email = targetArr[0];
34+
const pets = targetArr.slice(1);
35+
for (var i = 0; i < pets.length; i++) {
36+
let fullName = getPetFullName(pets[i]);
37+
console.log(fullName)
38+
await octokit.orgs.createInvitation({
39+
org: fullName,
40+
email,
41+
role: 'direct_member'
42+
})
43+
core.info(`Auto invited ${fullName}`);
44+
}
45+
46+
core.info('Adding a comment');
47+
await octokit.issues.createComment({
48+
owner,
49+
repo,
50+
issue_number: issueNumber,
51+
body: issueBody,
52+
})
53+
};
54+
55+
async function getOrganizations() {
56+
await axios.get(url).then(res =>{
57+
organizations = res.data.data
58+
},rej => {
59+
core.info(`Get Org ${rej}`);
60+
}).catch(err =>{
61+
core.info(`Get Org ${err}`);
62+
})
63+
};
64+
65+
function getPetFullName(name) {
66+
let r = organizations.find(o => o.name === name);
67+
return r ? r.fullName : null;
68+
};
69+
70+
(async () => {
71+
await getOrganizations();
72+
await main();
73+
})();

test.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GH_TOKEN=

0 commit comments

Comments
 (0)