Skip to content

Commit b8a9cff

Browse files
author
lucifer
committed
feat: 自动邀请
1 parent e820d1d commit b8a9cff

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

Diff for: config/index.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ const tobeIdentified = [
1919
"liandmin",
2020
"sunshineliu6",
2121
"Huzhixin00",
22-
"Leah-Luo",
22+
// "Leah-Luo",
2323
"HackBL",
24-
"mozro.0327",
24+
"mozro0327",
2525
"liucy0417",
2626
"watermelonDrip",
2727
"wonderful1234",
28-
"SWUFEzyf",
28+
// "SWUFEzyf",
2929
"suffocatingly0",
3030
"christ36",
3131
"awarmdevil",
3232
"NchuYJ",
3333
"zc-githubs",
34-
"paopaohua",
34+
// "paopaohua",
3535
"Critsu",
3636
"Placeholder",
3737
"Levix",
@@ -114,6 +114,25 @@ const tobeIdentified = [
114114

115115
"angusgenius",
116116
"lilyzhaoyilu",
117+
"FlorenceLLL",
118+
"zjsj",
119+
"andyyxw",
120+
"pkuphy",
121+
"zhangjihu0",
122+
"wz-hub",
123+
"bmxbmx3",
124+
"davont",
125+
"Lizhao-Liu ",
126+
"terrylijiayang",
127+
"shizukanaskytree",
128+
"taozi-taozi",
129+
"wanyongtao1988",
130+
"LzdFeiFei",
131+
"angusgenius",
132+
"lilyzhaoyilu",
133+
"ningali",
134+
"WIN0624",
135+
"Gjts",
117136
];
118137

119138
module.exports = {
@@ -149,6 +168,9 @@ module.exports = {
149168
{
150169
login: "15399618796",
151170
},
171+
{
172+
login: "Xeraphinite",
173+
},
152174
].concat(
153175
tobeIdentified.map((name) => ({
154176
login: name,

Diff for: middleware/passport.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fetch = require("node-fetch");
2+
const { Octokit } = require("@octokit/rest");
23
const { encrypt, decrypt } = require("../utils/crypto");
34
const { fail } = require("../utils/request");
45
const { secret, db, clientId } = require("../config/index");
@@ -62,11 +63,18 @@ module.exports = async function checkAuth(ctx, next) {
6263
...user,
6364
pay: !!db.find((q) => q.login === user.login),
6465
};
65-
// TODO: 如果不在组织中,自动邀请进 Github 组织
66-
// see #1 https://octokit.github.io/rest.js/v18#orgs-check-membership
67-
// see #2 https://github.com/octokit/octokit.js
68-
// see #3 https://github.com/thundergolfer/automated-github-organization-invites/blob/bb1bb3d42a330716f4dd5c49256245e4bde27489/web_app.rb
69-
ctx.session.user = u;
66+
try {
67+
const octokit = new Octokit({ auth: process.env.token });
68+
69+
octokit.rest.teams.addOrUpdateMembershipForUserInOrg({
70+
org: "leetcode-pp",
71+
team_slug: "91algo-4",
72+
username: user.login,
73+
});
74+
} catch (err) {
75+
console.log("自动邀请失败:", err);
76+
}
77+
7078
ctx.cookies.set(
7179
"token",
7280
encrypt(Buffer.from(JSON.stringify(u), "utf8")),

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@koa/cors": "^3.1.0",
13+
"@octokit/rest": "^18.5.3",
1314
"debug": "^4.1.1",
1415
"koa": "^2.7.0",
1516
"koa-bodyparser": "^4.2.1",

Diff for: test/invite.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { Octokit } = require("@octokit/rest");
2+
const octokit = new Octokit({ auth: process.env.token });
3+
4+
octokit.rest.teams.addOrUpdateMembershipForUserInOrg({
5+
org: "leetcode-pp",
6+
team_slug: "91algo-4",
7+
username: "rfhklwt",
8+
});

0 commit comments

Comments
 (0)