Skip to content

Commit

Permalink
refactor: ♻️ 🔊 convert some consola logs to logwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
slugb0t committed Dec 10, 2024
1 parent 104ae3e commit 4132e66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
36 changes: 18 additions & 18 deletions bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as express from "express";
import { consola } from "consola";
import { renderIssues, createIssue } from "./utils/renderer/index.js";
import dbInstance from "./db.js";
import yaml from "js-yaml";
import { logwatch } from "./utils/logwatch.js";
import {
checkEnvVariable,
isRepoEmpty,
Expand Down Expand Up @@ -654,7 +654,7 @@ export default async (app, { getRouter }) => {
issueBody.includes("<!-- @codefair-bot rerun-cwl-validation -->")
) {
try {
consola.start("Rerunning CWL Validation...");
logwatch.start("Rerunning CWL Validation...");

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

Expand Down Expand Up @@ -709,14 +709,14 @@ export default async (app, { getRouter }) => {
repo: repository.name,
});

consola.success("CWL Validation rerun successfully!");
logwatch.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);
logwatch.error(error.cause);
}
throw new Error("Error rerunning full repo validation", error);
}
Expand All @@ -725,7 +725,7 @@ export default async (app, { getRouter }) => {
if (
issueBody.includes("<!-- @codefair-bot rerun-full-repo-validation -->")
) {
consola.start("Rerunning full repository validation...");
logwatch.start("Rerunning full repository validation...");
try {
const license = await checkForLicense(context, owner, repository.name);
const citation = await checkForCitation(context, owner, repository.name);
Expand Down Expand Up @@ -773,15 +773,15 @@ export default async (app, { getRouter }) => {
const lastModified = await applyLastModifiedTemplate(issueBodyRemovedCommand);
await createIssue(context, owner, repository, ISSUE_TITLE, lastModified);
if (error.cause) {
consola.error(error.cause);
logwatch.error(error.cause);
}
throw new Error("Error rerunning full repo validation", error);
}
}

if (issueBody.includes("<!-- @codefair-bot rerun-license-validation -->")) {
// Run the license validation again
consola.start("Rerunning License Validation...");
logwatch.start("Rerunning License Validation...");
try {
const licenseRequest = await context.octokit.rest.licenses.getForRepo({
owner,
Expand All @@ -802,7 +802,7 @@ export default async (app, { getRouter }) => {

const { licenseId, licenseContent, licenseContentEmpty } = validateLicense(licenseRequest, existingLicense);

consola.info("License validation complete:", licenseId, licenseContent, licenseContentEmpty);
logwatch.info("License validation complete:", licenseId, licenseContent, licenseContentEmpty);

// Update the database with the license information
if (existingLicense) {
Expand Down Expand Up @@ -838,12 +838,15 @@ export default async (app, { getRouter }) => {
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) {
logwatch.error(error.cause);
}
throw new Error("Error rerunning license validation", error);
}
}

if (issueBody.includes("<!-- @codefair-bot rerun-metadata-validation -->")) {
consola.start("Validating metadata files...");
logwatch.start("Validating metadata files...");
try {
let metadata = await gatherMetadata(context, owner, repository);
let containsCitation = false,
Expand Down Expand Up @@ -930,20 +933,20 @@ export default async (app, { getRouter }) => {
const lastModified = await applyLastModifiedTemplate(issueBodyRemovedCommand);
await createIssue(context, owner, repository, ISSUE_TITLE, lastModified);
if (error.cause) {
consola.error(error.cause);
logwatch.error(error.cause);
}
throw new Error("Error rerunning metadata validation", error);
}
}

if (issueBody.includes("<!-- @codefair-bot publish-zenodo")) {
consola.start("Publishing to Zenodo...");
logwatch.start("Publishing to Zenodo...");
const issueBodyRemovedCommand = issueBody.substring(0, issueBody.indexOf("<!-- @codefair-bot publish-zenodo"));
const issueBodyNoArchiveSection = issueBodyRemovedCommand.substring(0, issueBody.indexOf("## FAIR Software Release"));
const badgeURL = `${CODEFAIR_DOMAIN}/dashboard/${owner}/${repository.name}/release/zenodo`;
const releaseBadge = `[![Create Release](https://img.shields.io/badge/Create_Release-00bcd4.svg)](${badgeURL})`
const { depositionId, releaseId, tagVersion, userWhoSubmitted } = parseZenodoInfo(issueBody);
consola.info("Parsed Zenodo info:", depositionId, releaseId, tagVersion, userWhoSubmitted);
logwatch.info("Parsed Zenodo info:", depositionId, releaseId, tagVersion, userWhoSubmitted);

try {
// 1. Get the metadata from the repository
Expand Down Expand Up @@ -1005,9 +1008,6 @@ export default async (app, { getRouter }) => {
const finalTemplate = await applyLastModifiedTemplate(issueBodyArchiveSection);
await createIssue(context, owner, repository, ISSUE_TITLE, finalTemplate);


consola.success("Updated the GitHub Issue!");

// Update the database with the Zenodo ID and the status
await db.zenodoDeposition.update({
data: {
Expand All @@ -1021,7 +1021,7 @@ export default async (app, { getRouter }) => {
}
});

consola.success("Updated the Zenodo deposition in the database!");
logwatch.success("Updated the Zenodo deposition in the database!");

await db.analytics.update({
data: {
Expand Down Expand Up @@ -1053,15 +1053,15 @@ export default async (app, { getRouter }) => {
}
});
if (error.cause) {
consola.error(`Error causes:`, { cause: error.cause });
logwatch.error(`Error causes:`, { cause: error.cause });
}
throw new Error(`Error publishing to Zenodo: ${error.message}`, { cause: error });
}
}

if (issueBody.includes("<!-- @codefair-bot re-render-dashboard -->")) {
// Run database queries in parallel using Promise.all
consola.start("Re-rendering issue dashboard...");
logwatch.start("Re-rendering issue dashboard...");
try {
const [licenseResponse, metadataResponse, cwlResponse] = await Promise.all([
db.licenseRequest.findUnique({
Expand Down
2 changes: 0 additions & 2 deletions bot/metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ export async function gatherMetadata(context, owner, repo) {
url = repoData.data.homepage;
}

consola.success("Metadata gathered!");

const codeMeta = {
name: repoData.data.name,
applicationCategory: null,
Expand Down

0 comments on commit 4132e66

Please sign in to comment.