From 281548e70339788894d709ad706dbbbcafe9829a Mon Sep 17 00:00:00 2001 From: Desmond Obisi Date: Sat, 3 Feb 2024 16:06:39 +0100 Subject: [PATCH] chore: clean up repository --- database/helpers/dbconnect.js | 4 ++-- event_badging/index.js | 4 ++-- event_badging/logic/calculate.badge.js | 8 ++++++- event_badging/logic/getResults.js | 1 + event_badging/logic/welcome.js | 1 + helpers/awardBadge.js | 8 ------- helpers/email_templates/failure.html | 10 ++++----- helpers/email_templates/success.html | 4 ++-- index.js | 6 ++++-- providers/github/auth.js | 28 ++++++++++++------------ providers/gitlab/APICalls.js | 14 ++++++------ providers/gitlab/auth.js | 30 +++++++++++++------------- routes/index.js | 4 ++-- 13 files changed, 62 insertions(+), 60 deletions(-) diff --git a/database/helpers/dbconnect.js b/database/helpers/dbconnect.js index badac39..aaad246 100644 --- a/database/helpers/dbconnect.js +++ b/database/helpers/dbconnect.js @@ -1,6 +1,6 @@ const sequelize = require("./sequelize"); -const dbconnect = async () => { +const dbConnect = async () => { try { await sequelize.authenticate(); try { @@ -17,4 +17,4 @@ const dbconnect = async () => { } }; -module.exports = dbconnect; +module.exports = dbConnect; diff --git a/event_badging/index.js b/event_badging/index.js index 5aa56c0..f883083 100644 --- a/event_badging/index.js +++ b/event_badging/index.js @@ -7,7 +7,7 @@ const { updateReadme, } = require("./logic/index.js"); -const event_badging = async (name, octokit, payload) => { +const eventBadging = async (name, octokit, payload) => { // perform actions on application issues only if (payload.issue.title.match(/event/i)) { // when applicant issue is open, welcome the applicant @@ -49,4 +49,4 @@ const event_badging = async (name, octokit, payload) => { } }; -module.exports = event_badging; +module.exports = eventBadging; diff --git a/event_badging/logic/calculate.badge.js b/event_badging/logic/calculate.badge.js index 36ad574..2b2648e 100644 --- a/event_badging/logic/calculate.badge.js +++ b/event_badging/logic/calculate.badge.js @@ -7,12 +7,14 @@ const calculateBadge = async (octokit, payload) => { ? (initialCheckCount = 4) : initialCheckCount; + // get the list of comments on the event issue const comments = await octokit.rest.issues.listComments({ owner: payload.repository.owner.login, repo: payload.repository.name, issue_number: payload.issue.number, }); + // filter out the comments that are checklists let checklists = comments.data.filter((comment) => { return ( comment.user.type == "Bot" && @@ -20,6 +22,7 @@ const calculateBadge = async (octokit, payload) => { ); }); + // get the total number of checks for each checklist let totalCheckCount = checklists.map(function (element) { return ( (element.body.match(/\[x\]/g) || []).length + @@ -31,6 +34,7 @@ const calculateBadge = async (octokit, payload) => { return element - initialCheckCount; }); + // get the number of checks for each checklist that are positive let positiveCheckCount = checklists.map(function (element) { let checkCount = +(element.body.match(/\[x\]/g) || []).length - initialCheckCount; @@ -38,6 +42,7 @@ const calculateBadge = async (octokit, payload) => { else return checkCount; }); + // get the percentage of checks for each checklist that are positive let percentages = positiveCheckCount.map(function (element) { let p = Math.floor((element / totalCheckCount[0]) * 100); return p; @@ -50,6 +55,7 @@ const calculateBadge = async (octokit, payload) => { }); reviewResult /= reviewerCount; + // assign bagde based on review result const badgeAssigned = reviewResult < 40 ? ["Pending", "D%26I-Pending-red"] @@ -75,7 +81,7 @@ const calculateBadge = async (octokit, payload) => { "" +
-    "D&I Badging badge state: " +
+    "d&i-badging-badge-state: " +
     badgeAssigned[0] +
     ""; messageObj = { diff --git a/event_badging/logic/getResults.js b/event_badging/logic/getResults.js index 92eb3de..c978849 100644 --- a/event_badging/logic/getResults.js +++ b/event_badging/logic/getResults.js @@ -10,6 +10,7 @@ const getResults = async (octokit, payload) => { resultsArray.reviewerCount + "\n"; + // comment results and badge on the issue await octokit.rest.issues .createComment({ owner: payload.repository.owner.login, diff --git a/event_badging/logic/welcome.js b/event_badging/logic/welcome.js index 85bbf2a..c7e9b21 100644 --- a/event_badging/logic/welcome.js +++ b/event_badging/logic/welcome.js @@ -7,6 +7,7 @@ const welcome = async (octokit, payload) => { path: ".github/applicant-welcome.md", }); + // send welcome message on the issue await octokit.rest.issues .createComment({ owner: payload.repository.owner.login, diff --git a/helpers/awardBadge.js b/helpers/awardBadge.js index 44f3663..6058912 100644 --- a/helpers/awardBadge.js +++ b/helpers/awardBadge.js @@ -1,14 +1,8 @@ -// const fs = require("fs"); -// const path = require("path"); -// const badgePath = path.join(__dirname, "../../assets/badge.svg"); const badgeLink = "https://raw.githubusercontent.com/badging/badging/main/src/assets/images/badges/bronze-badge.svg"; const awardBadge = async (octokit, owner, repoName) => { try { - // Read the SVG file content - // const svgContent = fs.readFileSync(badgePath, "utf8"); - // Read the existing README file content const { data: existingFile } = await octokit.rest.repos.getContent({ owner: owner, @@ -21,8 +15,6 @@ const awardBadge = async (octokit, owner, repoName) => { "base64" ).toString("utf8"); - // Combine the SVG content with the existing README content - // const updatedContent = `![Bronze badge](${svgContent})\n\n${existingContent}`; const updatedContent = `![Bronze badge](${badgeLink})\n\n${existingContent}`; // Create or update the README file with the modified content directly on the main branch diff --git a/helpers/email_templates/failure.html b/helpers/email_templates/failure.html index a108716..9126ed9 100644 --- a/helpers/email_templates/failure.html +++ b/helpers/email_templates/failure.html @@ -22,7 +22,7 @@ margin-bottom: 20px; } - .email_content { + .email-content { color: #555555; font-size: 16px; line-height: 1.5; @@ -64,17 +64,17 @@
email carousel

Badging Updates

-

+

Dear {{recipientName}},

@@ -88,7 +88,7 @@

Badging Updates

-

+

Once you have the missing information, please resubmit your project for review, and we'll be happy to reconsider it for the badge issuance.
diff --git a/helpers/email_templates/success.html b/helpers/email_templates/success.html index f7d84ad..98da70e 100644 --- a/helpers/email_templates/success.html +++ b/helpers/email_templates/success.html @@ -32,7 +32,7 @@ margin-bottom: 20px; } - .email_content { + .email-content { color: #555555; font-size: 16px; line-height: 1.5; @@ -58,7 +58,7 @@

Congratulations on Your DEI Badge!

-