From e2436ed6508df15b0cde849d6430f738d23a9a9f Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Mon, 14 Dec 2020 13:33:03 +0800 Subject: [PATCH] perf: add more info (#151) --- script/auto-invite.js | 25 +++++++++++++++++-------- script/check-application.js | 8 ++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/script/auto-invite.js b/script/auto-invite.js index 63fdf7c..1136168 100644 --- a/script/auto-invite.js +++ b/script/auto-invite.js @@ -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. @@ -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. ', ''); @@ -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, @@ -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; @@ -145,6 +152,8 @@ function getPetFullName(name) { }; (async () => { + console.log('Begin: auto invite start!'); await getOrganizations(); await main(); + console.log('End: auto invited end!'); })(); diff --git a/script/check-application.js b/script/check-application.js index 45d13f0..a371f40 100644 --- a/script/check-application.js +++ b/script/check-application.js @@ -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) { @@ -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, @@ -121,6 +125,7 @@ async function main() { labels: ['need accurate info'] }); } else { + console.log(`Success: check application success!`); await octokit.issues.addLabels({ owner, repo, @@ -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); } }; @@ -145,6 +151,8 @@ function getPetFullName(name) { }; (async () => { + console.log(`Begin: check application begin!`); await getOrganizations(); await main(); + console.log(`End: check application end!`); })();