Skip to content

Commit

Permalink
perf: add more info (zoo-js#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrkffgg authored Dec 14, 2020
1 parent 682cf79 commit e2436ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 17 additions & 8 deletions script/auto-invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
ISSUE_NUMBER,
} = process.env;
const issueAuth = ISSUE_AUTH || 'xrkffgg';
const issueNumber = ISSUE_NUMBER || 48;
const issueNumber = ISSUE_NUMBER || 149;

const issueBody = `🎉 Hi, @${issueAuth}. The invitation has been sent to the specified email address, please check! This issue will be closed. If you have any questions, please comment below.
Expand Down Expand Up @@ -47,6 +47,8 @@ async function main() {

if (val.startsWith('GitHub Email:')) {
email = val.replace('GitHub Email: ', '');
} else {
console.log('Error: get email failed!')
}
if (email && val.startsWith('1.') && val.length > 3) {
pet1 = val.replace('1. ', '');
Expand All @@ -69,7 +71,7 @@ async function main() {
const emailExp = new RegExp('^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$', '');

if ((!email || !emailExp.test(email)) || (!pet1 && !pet2 && !pet3 && !pet4 && !pet5)) {
core.info('empty');
core.info('Error: check auto invited failed!');
await octokit.issues.createComment({
owner,
repo,
Expand Down Expand Up @@ -118,12 +120,17 @@ async function main() {
async function invitePeople(email, pet) {
let org = getPetFullName(pet);
if (org) {
await octokit.orgs.createInvitation({
org,
email,
role: 'direct_member'
});
core.info(`Auto invited ${org}`);
try {
await octokit.orgs.createInvitation({
org,
email,
role: 'direct_member'
});
core.info(`Auto invited ${org}`);
} catch (err) {
console.log(`Error: invite ${org} error!`);
console.log(err);
}
} else {
core.info(`Get ${pet} fullName error!`);
return false;
Expand All @@ -145,6 +152,8 @@ function getPetFullName(name) {
};

(async () => {
console.log('Begin: auto invite start!');
await getOrganizations();
await main();
console.log('End: auto invited end!');
})();
8 changes: 8 additions & 0 deletions script/check-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ async function main() {

if (val.startsWith('GitHub Email:')) {
email = val.replace('GitHub Email: ', '');
} else {
console.log('Error: email is empty!')
}

if (email && val.startsWith('1.') && val.length > 3) {
pet1 = val.replace('1. ', '');
if (pet1) {
Expand Down Expand Up @@ -107,6 +110,7 @@ async function main() {
const emailExp = new RegExp('^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$', '');

if (!email || !emailExp.test(email) || (userNowApp === 0)) {
console.log(`Error: check application field!`);
await octokit.issues.createComment({
owner,
repo,
Expand All @@ -121,6 +125,7 @@ async function main() {
labels: ['need accurate info']
});
} else {
console.log(`Success: check application success!`);
await octokit.issues.addLabels({
owner,
repo,
Expand All @@ -135,6 +140,7 @@ async function getOrganizations() {
const res = await axios.get(url);
organizations = res.data.data;
} catch(err) {
console.log('Error: get org error!')
console.log(err);
}
};
Expand All @@ -145,6 +151,8 @@ function getPetFullName(name) {
};

(async () => {
console.log(`Begin: check application begin!`);
await getOrganizations();
await main();
console.log(`End: check application end!`);
})();

0 comments on commit e2436ed

Please sign in to comment.