Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes referenced issues #11

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions helpers/email_templates/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ <h1>Congratulations on Your DEI Badge!</h1>
<br />
<br />
We are thrilled to inform you that your recent review submission of your
Open Source Project has been recognized and rewarded an All In CHAOSS
DEI
<strong>{{badgeName}}</strong> badge.
Open Source Project has been recognized and rewarded a CHAOSS DEI
Project <strong>{{badgeName}}</strong> badge.
<br />
<br />
Once Again, congratulations on this well-deserved Badge!
Expand All @@ -98,14 +97,6 @@ <h1>Congratulations on Your DEI Badge!</h1>
<code>{{htmlLink}}</code>
<br />
<br />
In the coming 3-4 days, we will share a supplemental report on your
project's language inclusivity. This report will provide valuable
insights into how inclusive your project's language is to diversw
audiences. This report is only a supplement to your DEI Badge and has no
impact on current or future badges. The report will only be sent to this
email and can be used in any way that you see fit.
<br />
<br />
Thank you for your ongoing DEI efforts!
<br />
<br />
Expand Down
24 changes: 21 additions & 3 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 @@ -71,7 +72,7 @@ const getUserRepositories = async (octokit) => {
} catch (error) {
return {
repositories: null,
errors: [error.message],
errors: "GitHub API returning no repository(ies).",
};
}
};
Expand Down Expand Up @@ -137,7 +138,6 @@ const getFileContentAndSHA = async (octokit, repositoryFullName, filePath) => {
};
}
};

/**
* Scans a list of repositories to try and apply for a badge
* @param {*} userId Id of the user
Expand All @@ -159,7 +159,6 @@ const scanRepositories = async (userId, name, email, repositoryIds) => {
console.error(info_errors);
continue;
}

const { file, errors: file_errors } = await getFileContentAndSHA(
octokit,
info.fullName,
Expand All @@ -176,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 @@ -194,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
54 changes: 37 additions & 17 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const reposToBadge = async (req, res) => {
const userId = req.body.userId;
const provider = req.body.provider;
const repositoryIds = selectedRepos.map((repo) => repo.id);

if (!provider) {
res.status(400).send("provider missing");
return;
Expand All @@ -55,22 +54,43 @@ const reposToBadge = async (req, res) => {
}

// Process the selected repos as needed
if (provider === "github") {
const results = await github_helpers.scanRepositories(
user.id,
user.name,
user.email,
repositoryIds
);
res.status(200).json({ results });
} else if (provider === "gitlab") {
const results = await gitlab_helpers.scanRepositories(
user.id,
user.name,
user.email,
repositoryIds
);
res.status(200).json({ results });
if (process.env.NODE_ENV === "development") {
if (provider === "github") {
const results = await github_helpers.scanRepositories(
user.id,
user.name,
user.email,
selectedRepos
);
res.status(200).json({ results });
} else if (provider === "gitlab") {
const results = await gitlab_helpers.scanRepositories(
user.id,
user.name,
user.email,
selectedRepos
);
res.status(200).json({ results });
}
} else if (process.env.NODE_ENV === "production") {
// process the selected repositories in production
if (provider === "github") {
const results = await github_helpers.scanRepositories(
user.id,
user.name,
user.email,
repositoryIds
);
res.status(200).json({ results });
} else if (provider === "gitlab") {
const results = await gitlab_helpers.scanRepositories(
user.id,
user.name,
user.email,
repositoryIds
);
res.status(200).json({ results });
}
} else {
res.status(400).send(`Unknown provider: ${provider}`);
}
Expand Down