Skip to content

Commit

Permalink
fix: 🐛 update logging parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
slugb0t committed Dec 9, 2024
1 parent d4c2335 commit e4428f2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 57 deletions.
119 changes: 65 additions & 54 deletions bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,62 +653,73 @@ export default async (app, { getRouter }) => {
if (
issueBody.includes("<!-- @codefair-bot rerun-cwl-validation -->")
) {
consola.start("Rerunning CWL Validation...");

const cwl = await getCWLFiles(context, owner, repository.name);

// Remove the section from the issue body starting from ## Language Specific Standards
const slicedBody = issueBody.substring(
0,
issueBody.indexOf("## Language Specific Standards"),
);

const cwlObject = {
contains_cwl_files: cwl.length > 0 || false,
files: cwl,
removed_files: [],
};

const cwlExists = await db.cwlValidation.findUnique({
where: {
repository_id: repository.id,
},
});

if (cwlExists) {
cwlObject.contains_cwl_files = cwlExists.contains_cwl_files;

if (cwlExists.files.length > 0) {
// Remove the files that are not in cwlObject
const cwlFilePaths = cwlObject.files.map((file) => file.path);
cwlObject.removed_files = cwlExists.files.filter((file) => {
return !cwlFilePaths.includes(file.path);
});
try {
consola.start("Rerunning CWL Validation...");

const cwl = await getCWLFiles(context, owner, repository.name);

// Remove the section from the issue body starting from ## Language Specific Standards
const slicedBody = issueBody.substring(
0,
issueBody.indexOf("## Language Specific Standards"),
);

const cwlObject = {
contains_cwl_files: cwl.length > 0 || false,
files: cwl,
removed_files: [],
};

const cwlExists = await db.cwlValidation.findUnique({
where: {
repository_id: repository.id,
},
});

if (cwlExists) {
cwlObject.contains_cwl_files = cwlExists.contains_cwl_files;

if (cwlExists.files.length > 0) {
// Remove the files that are not in cwlObject
const cwlFilePaths = cwlObject.files.map((file) => file.path);
cwlObject.removed_files = cwlExists.files.filter((file) => {
return !cwlFilePaths.includes(file.path);
});
}
}

const subjects = {
cwl: cwlObject,
};

// This will also update the database
const updatedIssueBody = await applyCWLTemplate(
subjects,
slicedBody,
repository,
owner,
context,
);

// Update the issue with the new body
await context.octokit.issues.update({
body: updatedIssueBody,
issue_number: context.payload.issue.number,
owner,
repo: repository.name,
});

consola.success("CWL Validation rerun successfully!");
} catch (error) {
// Remove the command from the issue body
const issueBodyRemovedCommand = issueBody.substring(0, issueBody.indexOf(`<sub><span style="color: grey;">Last updated`));
const lastModified = await applyLastModifiedTemplate(issueBodyRemovedCommand);
await createIssue(context, owner, repository, ISSUE_TITLE, lastModified);
if (error.cause) {
consola.error(error.cause);
}
throw new Error("Error rerunning full repo validation", error);
}

const subjects = {
cwl: cwlObject,
};

// This will also update the database
const updatedIssueBody = await applyCWLTemplate(
subjects,
slicedBody,
repository,
owner,
context,
);

// Update the issue with the new body
await context.octokit.issues.update({
body: updatedIssueBody,
issue_number: context.payload.issue.number,
owner,
repo: repository.name,
});

consola.success("CWL Validation rerun successfully!");
}

if (
Expand Down
7 changes: 4 additions & 3 deletions bot/metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,18 @@ export async function validateMetadata(metadataInfo, fileType, repository) {
);

if (!response.ok) {
const data = await response.json();
logwatch.error(
{
status: response.status,
error: response.json(),
error: data,
file: "codemeta.json",
},
true,
);
throw new Error(
"Error validating the codemeta.json file",
response.json(),
data,
);
}
const data = await response.json();
Expand All @@ -461,7 +462,7 @@ export async function validateMetadata(metadataInfo, fileType, repository) {

return data.message === "valid";
} catch (error) {
logwatch.error("error parsing the codemeta.json file");
logwatch.error(`error parsing the codemeta.json file: ${error}`);
consola.error("Error validating the codemeta.json file", error);

return false;
Expand Down
5 changes: 5 additions & 0 deletions ui/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ declare module 'vue' {
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCollapse: typeof import('naive-ui')['NCollapse']
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NDatePicker: typeof import('naive-ui')['NDatePicker']
NDivider: typeof import('naive-ui')['NDivider']
NDropdown: typeof import('naive-ui')['NDropdown']
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
NFlex: typeof import('naive-ui')['NFlex']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NInput: typeof import('naive-ui')['NInput']
NModal: typeof import('naive-ui')['NModal']
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
NPopover: typeof import('naive-ui')['NPopover']
NRadio: typeof import('naive-ui')['NRadio']
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NTag: typeof import('naive-ui')['NTag']
NTooltip: typeof import('naive-ui')['NTooltip']
Expand Down
5 changes: 5 additions & 0 deletions validator/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,8 @@ def post(self):
"error": str(e.message + " at " + str(e.validator_value)),
"version": codemeta_version,
}, 200
except Exception as e:
return {
"message": "Validation Error",
"error": f"Unexpected error: {str(e)}",
}, 400

0 comments on commit e4428f2

Please sign in to comment.