Skip to content

Commit

Permalink
Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
kaxada committed Dec 21, 2023
1 parent 93f2f5d commit 09d044a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
42 changes: 36 additions & 6 deletions providers/github/APICalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ const getFileContentAndSHA = async (octokit, repositoryFullName, filePath) => {
* @param {*} email User email used to send them emails with the results
* @param {*} repositoryIds List of repositories id to scan
*/

/**
* Declaring the 'DEItempate variable as a global scrope
* so that it can be exported and used in comparing it to the
* DEI content in the gitlab repositories
*/

let DEItemplate;

const scanRepositories = async (userId, name, email, repositoryIds) => {
const octokit = new Octokit();
let results = [];
Expand All @@ -169,13 +178,20 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
}

try {
// Check if the repo was badged before
const existingRepo = await Repo.findOne({
where: { githubRepoId: info.id, DEICommitSHA: file.sha },
});

if (file.content) {
// retrieve existing repo ID from Database
const existingRepo = await Repo.findOne({
where: { githubRepoId: info.id, DEICommitSHA: file.sha },
});

// retrieve DEI template as stored at => https://github.com/badging/badging/blob/main/Template.DEI.md
DEItemplate = await getFileContentAndSHA(
octokit,
"badging/badging",
"Template.DEI.md"
);
if (existingRepo) {
// Check if the repo was badged before
// Compare the DEICommitSHA with the existing repo's DEICommitSHA
if (existingRepo.DEICommitSHA !== file.sha) {
bronzeBadge(
Expand All @@ -192,6 +208,19 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
// Handle case when DEI.md file is not changed
results.push(`${info.url} was already badged`);
}
} else if (DEItemplate) {
// check whether DEI file to be badged has content similar to DEI Template
try {
if (file.content === DEItemplate.file.content) {
results.push(
`Please provide project specific DEI content for ${info.url} different from the template information`
);
}
} catch (error) {
console.error(
"DEI template cannot be found at the original location 'https://github.com/badging/badging/blob/main/Template.DEI.md'"
);
}
} else {
// Repo not badged before, badge it
bronzeBadge(
Expand All @@ -207,7 +236,7 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
}
}
} catch (error) {
console.error(error.message);
console.error("DEI.md file has no content");
}
}

Expand All @@ -228,4 +257,5 @@ module.exports = {
getUserInfo,
getUserRepositories,
scanRepositories,
DEItemplate,
};
14 changes: 14 additions & 0 deletions providers/gitlab/APICalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const axios = require("axios");
const Repo = require("../../database/models/repo.model.js");
const bronzeBadge = require("../../badges/bronzeBadge.js");
const mailer = require("../../helpers/mailer.js");
const { DEItemplate } = require("../github/APICalls.js");

/**
* Calls the GitLab API to get the user info.
Expand Down Expand Up @@ -191,6 +192,19 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
// Handle case when DEI.md file is not changed
results.push(`${info.url} was already badged`);
}
} else if (DEItemplate) {
// check whether DEI file to be badged has content similar to DEI Template
try {
if (file.content === DEItemplate.file.content) {
results.push(
`Please provide project specific DEI content for ${info.url} different from the template information`
);
}
} catch (error) {
console.error(
"DEI template cannot be found at the original location 'https://github.com/badging/badging/blob/main/Template.DEI.md'"
);
}
} else {
// Repo not badged before, badge it
bronzeBadge(
Expand Down

0 comments on commit 09d044a

Please sign in to comment.