Skip to content

Commit

Permalink
refactor: ♻️ const declaration on validateCWLFile function call
Browse files Browse the repository at this point in the history
  • Loading branch information
slugb0t committed Aug 8, 2024
1 parent d44ae7b commit 39d4f8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
3 changes: 0 additions & 3 deletions bot/utils/citation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export async function checkForCitation(context, owner, repo) {
}
}


// TODO: Verify if this is still needed
export async function gatherCitationInfo(context, owner, repo) {
// Verify there is no PR open already for the CITATION.cff file
Expand Down Expand Up @@ -86,9 +85,7 @@ export async function gatherCitationInfo(context, owner, repo) {
// Get the keywords of the repo
let keywords = [];
if (repoData.data.topics != null && repoData.data.topics.length > 0) {
// console.log(repoData.data.topics);
keywords = repoData.data.topics;
// console.log(keywords);
}

// Begin creating json for CITATION.cff file
Expand Down
11 changes: 5 additions & 6 deletions bot/utils/license/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/**
* * Check if a license is found in the repository
*
* @param {object} context - The GitHub context object
*
* @param {object} context - The GitHub context object
* @param {string} owner - The owner of the repository
* @param {string} repo - The name of the repository
* @returns {boolean} - Returns true if a license is found in the repository, false otherwise
Expand All @@ -27,12 +27,11 @@ export async function checkForLicense(context, owner, repo) {
}
}


/**
* * Create a new license file in the repository
*
* @param {object1} context - The GitHub context object
* @param {string} owner - The owner of the repository
*
* @param {object1} context - The GitHub context object
* @param {string} owner - The owner of the repository
* @param {string} repo - The name of the repository
* @param {string} license - The license identifier
*/
Expand Down
24 changes: 9 additions & 15 deletions bot/utils/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function removeTokenFromUrlInString(inputString) {

// Replace each found URL in the string after removing the token
return inputString.replace(urlRegex, (url) => {
console.log(url);
return url.replace(/\?token=[^:]+/, "");
});
}
Expand Down Expand Up @@ -271,12 +270,6 @@ export async function applyCWLTemplate(
context,
) {
const privateRepo = await isRepoPrivate(context, owner, repository.name);
// If the repository is private and contains CWL files, we cannot validate them
// if (privateRepo && subjects.cwl.contains_cwl) {
// baseTemplate += `\n\n## CWL Validations ❌\n\n> [!WARNING]\n> Your repository is private. Codefair will not be able to validate any CWL files for you. You can check the CWL file yourself using the [cwltool validator](https://cwltool.readthedocs.io/en/latest/)`;
// return baseTemplate;
// }

let url = `${CODEFAIR_DOMAIN}/view/cwl-validation/`;
const identifier = createId();
const cwlCollection = dbInstance.getDb().collection("cwlValidation");
Expand Down Expand Up @@ -315,8 +308,6 @@ export async function applyCWLTemplate(
}
}

console.log(subjects);
console.log(subjects.cwl.contains_cwl);
if (!subjects.cwl.contains_cwl) {
console.log("no cwl files in repo");
// NO CWL files found in the repository, return the base template without appending anything
Expand All @@ -325,7 +316,6 @@ export async function applyCWLTemplate(

// No new CWL files were found in the repository but some were validated already
const cwlBadge = `[![CWL](https://img.shields.io/badge/View_CWL_Report-0ea5e9.svg)](${url})`;
console.log("repo has cwl files but no new ones to validate");
baseTemplate += `\n\n## CWL Validations\n\nNo new CWL files were found in the repository but ***${existingCWL.files.length}/${existingCWL.files.length}*** that were validated already are considered valid by the [cwltool validator](https://cwltool.readthedocs.io/en/latest/).\n\n<details>\n<summary>Summary of the validation report</summary>\n\n| File | Status |\n| :---- | :----: |\n${tableContent}</details>\n\nTo view the full report of each CWL file or rerun the validation, click the "View CWL Report" button below.\n\n${cwlBadge}`;
} else {
const cwlFiles = [];
Expand All @@ -336,10 +326,12 @@ export async function applyCWLTemplate(
for (const file of subjects.cwl.files) {
const fileSplit = file.name.split(".");
if (fileSplit.includes("cwl")) {
let [isValidCWL, validationMessage] = await validateCWLFile(
const [isValidCWL, validationMessage] = await validateCWLFile(
file.download_url,
);

let validationMessageForPrivate = validationMessage;

if (!isValidCWL && validOverall) {
validOverall = false;
}
Expand All @@ -348,10 +340,10 @@ export async function applyCWLTemplate(
failedCount += 1;
}

if (isRepoPrivate) {
if (privateRepo) {
console.log("Private repo, removing token from validation message");
validationMessage = removeTokenFromUrlInString(validationMessage);
console.log(validationMessage);
validationMessageForPrivate =
removeTokenFromUrlInString(validationMessage);
}

const newDate = Date.now();
Expand All @@ -360,7 +352,9 @@ export async function applyCWLTemplate(
last_modified: newDate,
last_validated: newDate,
path: file.path,
validation_message: validationMessage,
validation_message: privateRepo
? validationMessageForPrivate
: validationMessage,
validation_status: isValidCWL ? "valid" : "invalid",
});

Expand Down

0 comments on commit 39d4f8b

Please sign in to comment.