Skip to content

Commit

Permalink
includes check for DEI.md file against template. (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 42a8298
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions providers/github/APICalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Octokit } = require("@octokit/rest");
const Repo = require("../../database/models/repo.model.js");
const bronzeBadge = require("../../badges/bronzeBadge.js");
const mailer = require("../../helpers/mailer.js");
const axios = require("axios");

/**
* Calls the GitHub API to get the user info.
Expand Down Expand Up @@ -174,6 +175,20 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
where: { githubRepoId: info.id, DEICommitSHA: file.sha },
});

// retrieve DEI template
const template_content = await axios.get(
"https://api.github.com/repos/badging/badging/contents/Template.DEI.md"
);
const template = Buffer.from(
template_content.data.content,
"base64"
).toString();

console.log({
repo: file.content,
template_to_test: template,
});

if (file.content) {
if (existingRepo) {
// Compare the DEICommitSHA with the existing repo's DEICommitSHA
Expand All @@ -192,6 +207,11 @@ 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 (file.content && file.content === template) {
// check if file content is copy/paste from template
results.push(
`Please provide DEI information specific to ${info.url} by editing the template`
);
} else {
// Repo not badged before, badge it
bronzeBadge(
Expand Down
19 changes: 19 additions & 0 deletions providers/gitlab/APICalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
where: { gitlabRepoId: info.id, DEICommitSHA: file.sha },
});

// retrieve DEI template
const template_content = await axios.get(
"https://api.github.com/repos/badging/badging/contents/Template.DEI.md"
);
const template = Buffer.from(
template_content.data.content,
"base64"
).toString();

console.log({
repo: file.content,
template_to_test: template,
});

if (file.content) {
if (existingRepo) {
// Compare the DEICommitSHA with the existing repo's DEICommitSHA
Expand All @@ -191,6 +205,11 @@ 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 (file.content && file.content === template) {
// check if file content is copy/paste from template
results.push(
`Please provide DEI information specific to ${info.url} by editing the template`
);
} else {
// Repo not badged before, badge it
bronzeBadge(
Expand Down

0 comments on commit 42a8298

Please sign in to comment.