Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into staging
  • Loading branch information
megasanjay committed Aug 9, 2024
2 parents 3e61a06 + 7f2b6c2 commit 1225839
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
40 changes: 28 additions & 12 deletions bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ checkEnvVariable("MONGODB_DB_NAME");
checkEnvVariable("GITHUB_APP_NAME");
checkEnvVariable("CODEFAIR_APP_DOMAIN");

// sourcery skip: use-object-destructuring
// const GITHUB_APP_NAME = process.env.GITHUB_APP_NAME;
const ISSUE_TITLE = `FAIR Compliance Dashboard`;
const CLOSED_ISSUE_BODY = `Codefair has been disabled for this repository. If you would like to re-enable it, please reopen this issue.`;

/**
* This is the main entrypoint to your Probot app
Expand Down Expand Up @@ -55,22 +54,19 @@ export default async (app, { getRouter }) => {
app.on(
["installation.created", "installation_repositories.added"],
async (context) => {
const repositories =
context.payload.repositories || context.payload.repositories_added;
const owner = context.payload.installation.account.login;
let applyActionLimit = false;
const actionCount = 0;
let applyActionLimit = false;
let repoCount = 0;
const repositories =
context.payload.repositories || context.payload.repositories_added;

// shows all repos you've installed the app on
for (const repository of repositories) {
repoCount++;
// TODO: Verify if we want to increase amount of actions needed by one every 5 repos
// if (repoCount % 5 === 0) {
// actionCount--;
// }

if (repoCount > 5) {
consola.info(`Applying action limit to ${repository.name}`);
applyActionLimit = true;
}

Expand Down Expand Up @@ -241,6 +237,7 @@ export default async (app, { getRouter }) => {
}

if (installation?.action && installation?.action_count >= 4) {
consola.info("Removing action limit for", repository.name);
installationCollection.updateOne(
{ repositoryId: repository.id },
{
Expand Down Expand Up @@ -395,9 +392,30 @@ export default async (app, { getRouter }) => {
repositoryId: repository.id,
});
if (installation?.action && installation?.action_count < 4) {
installationCollection.updateOne(
{ repositoryId: repository.id },
{
$set: {
action_count: installation.action_count + 1,
},
},
);
return;
}

if (installation?.action && installation?.action_count >= 4) {
consola.info("Removing action limit for", repository.name);
installationCollection.updateOne(
{ repositoryId: repository.id },
{
$set: {
action: false,
action_count: installation.action_count + 1,
},
},
);
}

if (definedPRTitles.includes(prTitle)) {
const prInfo = {
title: prTitle,
Expand Down Expand Up @@ -562,10 +580,8 @@ export default async (app, { getRouter }) => {

if (context.payload.action === "closed") {
// Update the body of the issue to reflect that the repository is disabled
const issueBody = `Codefair has been disabled for this repository. If you would like to re-enable it, please reopen this issue.`;

await context.octokit.issues.update({
body: issueBody,
body: CLOSED_ISSUE_BODY,
issue_number: context.payload.issue.number,
owner: repository.owner.login,
repo: repository.name,
Expand Down
9 changes: 5 additions & 4 deletions bot/utils/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export async function applyCWLTemplate(
}
url = `${CODEFAIR_DOMAIN}/view/cwl-validation/${identifier}`;
if (!existingCWL) {
// Entry does not exist in the db, create a new one
// Entry does not exist in the db, create a new one (no old files exist, first time seeing cwl files)
const newDate = Date.now();
await cwlCollection.insertOne({
contains_cwl_files: subjects.cwl.contains_cwl,
Expand All @@ -377,13 +377,14 @@ export async function applyCWLTemplate(
updated_at: newDate,
});
} else {
// Get the identifier of the existing cwl request
// An entry exists in the db, thus possible old files exist (merge both lists)
const newFiles = [...existingCWL.files, ...cwlFiles];
await cwlCollection.updateOne(
{ repositoryId: repository.id },
{
$set: {
contains_cwl_files: true,
files: [...existingCWL.files, ...cwlFiles], // Join the existing files with the new ones
contains_cwl_files: newFiles.length > 0 ? true : false,
files: newFiles,
overall_status: validOverall ? "valid" : "invalid",
updated_at: Date.now(),
},
Expand Down

0 comments on commit 1225839

Please sign in to comment.