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) => {
"";
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 @@
+
Dear {{recipientName}},
@@ -88,7 +88,7 @@
+
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 @@
+
Dear {{recipientName}},
diff --git a/index.js b/index.js
index b113353..fc6f76a 100644
--- a/index.js
+++ b/index.js
@@ -1,11 +1,13 @@
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
-const dbconnect = require("./database/helpers/dbconnect");
+const dbConnect = require("./database/helpers/dbconnect");
const routes = require("./routes/index.js");
require("dotenv").config();
const app = express();
+
+// middlewares
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(
@@ -20,7 +22,7 @@ routes.setupRoutes(app);
(async () => {
try {
- await dbconnect().then(() => {
+ await dbConnect().then(() => {
app.listen(process.env.PORT, () => {
console.log(`server listening on port ${process.env.PORT}`);
});
diff --git a/providers/github/auth.js b/providers/github/auth.js
index a5d1b35..a02d3ed 100644
--- a/providers/github/auth.js
+++ b/providers/github/auth.js
@@ -72,28 +72,28 @@ const requestAccessToken = async (code) => {
const handleOAuthCallback = async (req, res) => {
const code = req.body.code ?? req.query.code;
- const { access_token, errors: access_token_errors } =
+ const { access_token: accessToken, errors: accessTokenErrors } =
await requestAccessToken(code);
- if (access_token_errors.length > 0) {
- res.status(500).send(access_token_errors.join());
+ if (accessTokenErrors.length > 0) {
+ res.status(500).send(accessTokenErrors.join());
return;
}
- const octokit = new Octokit({ auth: `${access_token}` });
+ const octokit = new Octokit({ auth: `${accessToken}` });
// Authenticated user details
- const { user_info, errors: user_info_errors } = await getUserInfo(octokit);
- if (user_info_errors.length > 0) {
- res.status(500).send(user_info_errors.join());
+ const { user_info: userInfo, errors: userInfoErrors } = await getUserInfo(octokit);
+ if (userInfoErrors.length > 0) {
+ res.status(500).send(userInfoErrors.join());
return;
}
// Save user to database
const savedUser = await saveUser(
- user_info.login,
- user_info.name,
- user_info.email,
- user_info.id,
+ userInfo.login,
+ userInfo.name,
+ userInfo.email,
+ userInfo.id,
null
);
if (!savedUser) {
@@ -102,10 +102,10 @@ const handleOAuthCallback = async (req, res) => {
}
// Public repos they maintain, administer, or own
- const { repositories, errors: repositories_errors } =
+ const { repositories, errors: repositoriesErrors } =
await getUserRepositories(octokit);
- if (repositories_errors.length > 0) {
- res.status(500).send(repositories_errors.join());
+ if (repositoriesErrors.length > 0) {
+ res.status(500).send(repositoriesErrors.join());
return;
}
diff --git a/providers/gitlab/APICalls.js b/providers/gitlab/APICalls.js
index e00ac32..0a99541 100644
--- a/providers/gitlab/APICalls.js
+++ b/providers/gitlab/APICalls.js
@@ -163,20 +163,20 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
try {
for (const repositoryId of repositoryIds) {
- const { info, errors: info_errors } = await getRepositoryInfo(
+ const { info, errors: infoErrors } = await getRepositoryInfo(
repositoryId
);
- if (info_errors.length > 0) {
- console.error(info_errors);
+ if (infoErrors.length > 0) {
+ console.error(infoErrors);
continue;
}
- const { file, errors: file_errors } = await getFileContentAndSHA(
+ const { file, errors: fileErrors } = await getFileContentAndSHA(
repositoryId,
"DEI.md",
info.defaultBranch
);
- if (file_errors.length > 0) {
+ if (fileErrors.length > 0) {
results.push(`${info.url} does not have a DEI.md file`);
continue;
}
@@ -188,11 +188,11 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
});
// retrieve DEI template
- const template_content = await axios.get(
+ const templateContent = await axios.get(
"https://api.github.com/repos/badging/badging/contents/Template.DEI.md"
);
const template = Buffer.from(
- template_content.data.content,
+ templateContent.data.content,
"base64"
).toString();
diff --git a/providers/gitlab/auth.js b/providers/gitlab/auth.js
index 62317c4..25e9db4 100644
--- a/providers/gitlab/auth.js
+++ b/providers/gitlab/auth.js
@@ -68,29 +68,29 @@ const requestAccessToken = async (code) => {
const handleOAuthCallback = async (req, res) => {
const code = req.body.code ?? req.query.code;
- const { access_token, errors: access_token_errors } =
+ const { access_token: accessToken, errors: accessTokenErrors } =
await requestAccessToken(code);
- if (access_token_errors.length > 0) {
- res.status(500).send(access_token_errors.join());
+ if (accessTokenErrors.length > 0) {
+ res.status(500).send(accessTokenErrors.join());
return;
}
// Authenticated user details
- const { user_info, errors: user_info_errors } = await getUserInfo(
- access_token
+ const { user_info: userInfo, errors: userInfoErrors } = await getUserInfo(
+ accessToken
);
- if (user_info_errors.length > 0) {
- res.status(500).send(user_info_errors.join());
+ if (userInfoErrors.length > 0) {
+ res.status(500).send(userInfoErrors.join());
return;
}
// Save user to database
const savedUser = await saveUser(
- user_info.login,
- user_info.name,
- user_info.email,
+ userInfo.login,
+ userInfo.name,
+ userInfo.email,
null,
- user_info.id
+ userInfo.id
);
if (!savedUser) {
res.status(500).send("Error saving user info");
@@ -98,10 +98,10 @@ const handleOAuthCallback = async (req, res) => {
}
// Public repos they maintain, administer, or own
- const { repositories, errors: repositories_errors } =
- await getUserRepositories(access_token);
- if (repositories_errors.length > 0) {
- res.status(500).send(repositories_errors.join());
+ const { repositories, errors: repositoriesErrors } =
+ await getUserRepositories(accessToken);
+ if (repositoriesErrors.length > 0) {
+ res.status(500).send(repositoriesErrors.join());
return;
}
diff --git a/routes/index.js b/routes/index.js
index 8623269..f6770e5 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -1,6 +1,6 @@
const { findUser } = require("../database/controllers/user.controller.js");
const Repo = require("../database/models/repo.model.js");
-const event_badging = require("../event_badging/index.js");
+const eventBadging = require("../event_badging/index.js");
const github_helpers = require("../providers/github/APICalls.js");
const gitlab_helpers = require("../providers/gitlab/APICalls.js");
const {
@@ -172,7 +172,7 @@ const setupRoutes = (app) => {
const octokit = await githubApp.getInstallationOctokit(
payload.installation.id
);
- event_badging(name, octokit, payload);
+ eventBadging(name, octokit, payload);
console.info(`Received ${name} event from Github`);
res.send("ok");
});