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

Merge: 🔀 merge main into staging #66

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ All notable changes the Codefair App will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


## v.2.0.1 - 2024-09-03

### Identifier

https://doi.org/10.5281/zenodo.13651177

### Added

- Added a migration script to update the database for users who may try to access the dashboard before the v2.0.0 bot has ran on all their repositories.
- Added badges to the CWL card on the dashboard to show the overall status of the CWL validations.

### Fixed

- Fixed a bug where the bot would updated the overall status of the CWL validation on the database.
- Link generator for Codefair repository settings was fixed to correctly generate the link for a user or repository.

### Removed

- Removed references to the action key in the database as it was not being used.


## v.2.0.0 - 2024-08-29

### Identifier
Expand Down
6 changes: 3 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ message: If you use this software, please cite it using the metadata from this f
type: software
identifiers:
- type: doi
value: https://doi.org/10.5281/zenodo.13544387
value: https://doi.org/10.5281/zenodo.13651177
abstract: "Codefair is a free and open source GitHub app that acts as your
personal assistant when it comes to making your research software reusable and
especially complying with the Findable, Accessible, Interoperable, Reusable
Expand All @@ -33,5 +33,5 @@ keywords:
- software
license: MIT
repository-code: https://github.com/fairdataihub/codefair-app
version: 2.0.0
date-released: 2024-08-29
version: 2.0.1
date-released: 2024-09-03
2 changes: 1 addition & 1 deletion bot/cwl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export async function applyCWLTemplate(

// Check if the overall status is still valid
for (const file of newFiles) {
if (file.overall_status === "invalid") {
if (file.validation_status === "invalid") {
validOverall = false;
break;
}
Expand Down
115 changes: 115 additions & 0 deletions bot/dev-migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import fs from "fs";
import dotenv from "dotenv";
import { MongoClient } from "mongodb";
import { consola } from "consola";

if (process.env.NODE_ENV !== "production") {
dotenv.config({
path: ".env",
});
}

if (!process.env.MONGODB_URI) {
throw new Error("Please define the MONGODB_URI environment variable");
}

if (!process.env.MONGODB_DB_NAME) {
throw new Error("Please define the MONGODB_DB_NAME environment variable");
}

const uri = process.env.MONGODB_URI;
const dbName = process.env.MONGODB_DB_NAME;
const devDbName = `${dbName}-migrations-test`;

// Create a new MongoClient
const client = new MongoClient(uri);

await client.connect();

const database = client.db(dbName);

if (!database) {
throw new Error("Database not found");
}

const devDatabase = client.db(devDbName);

// FOR DEV ONLY
// Clone the original database
// Get the list of collections in the original database
consola.start("Cloning the original database...");

const collections = await database.listCollections().toArray();

for (const collection of collections) {
const collectionName = collection.name;

// Get the collection
const dbCollection = database.collection(collectionName);

// Get the documents in the collection
const documents = await dbCollection.find().toArray();

// Drop the collection in the new database if it exists
await devDatabase.dropCollection(collectionName).catch(() => {});

// Create a new collection in the new database
const newCollection = devDatabase.collection(collectionName);

// Insert the documents into the new collection
if (documents.length > 0) {
await newCollection.insertMany(documents);
}
}

consola.success("Database cloned!");

// Get the list of files in the migrations folder
const files = fs.readdirSync("./migrations");

// Order the files by name
files.sort();

const migrationsCollection = devDatabase.collection("migrations");

for (const file of files) {
// Get the file name without the extension
const migrationId = file.replace(".ts", "");

// Check if the migration has already been applied
const migration = await migrationsCollection.findOne({
migration_id: migrationId,
});

if (migration) {
consola.warn(`Migration ${migrationId} has already been applied`);
continue;
}

// Import the migration file
const { default: migrationFunction } = await import(
`./migrations/${migrationId}`
);

consola.start(`Applying migration ${migrationId}`);

try {
// Run the migration
await migrationFunction(uri, devDbName, migrationId);
} catch (error) {
consola.error(`Error applying migration ${migrationId}: ${error.message}`);
throw error;
}

consola.success(`Migration ${migrationId} has been applied!`);

// Insert the migration into the migrations collection
// await migrationsCollection.insertOne({
// migration_id: migrationId,
// created_at: new Date(),
// });
}

await client.close();

process.exit();
11 changes: 3 additions & 8 deletions bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export default async (app, { getRouter }) => {
await verifyInstallationAnalytics(
context,
repository,
applyActionLimit,
actionCount,
latestCommitInfo,
);
Expand Down Expand Up @@ -259,7 +258,7 @@ export default async (app, { getRouter }) => {
installationCollection,
);

if (installation?.action && installation?.action_count > 0) {
if (installation?.action_count > 0) {
consola.warn(
"Action limit count down:",
installation.action_count,
Expand Down Expand Up @@ -288,7 +287,6 @@ export default async (app, { getRouter }) => {
{ repositoryId: repository.id },
{
$set: {
action: false,
action_count: 0,
latestCommitDate: latestCommitInfo.latestCommitDate,
latestCommitMessage: latestCommitInfo.latestCommitMessage,
Expand Down Expand Up @@ -452,7 +450,7 @@ export default async (app, { getRouter }) => {
const installation = await installationCollection.findOne({
repositoryId: repository.id,
});
if (installation?.action && installation?.action_count > 0) {
if (installation?.action_count > 0) {
installationCollection.updateOne(
{ repositoryId: repository.id },
{
Expand All @@ -470,7 +468,6 @@ export default async (app, { getRouter }) => {
{ repositoryId: repository.id },
{
$set: {
action: false,
action_count: 0,
},
},
Expand Down Expand Up @@ -543,7 +540,7 @@ export default async (app, { getRouter }) => {
installationCollection,
);

if (installation?.action && installation?.action_count > 0) {
if (installation?.action_count > 0) {
installationCollection.updateOne(
{ repositoryId: context.payload.repository.id },
{ $set: { action_count: installation.action_count - 1 } },
Expand All @@ -557,7 +554,6 @@ export default async (app, { getRouter }) => {
{ repositoryId: context.payload.repository.id },
{
$set: {
action: false,
action_count: 0,
},
},
Expand Down Expand Up @@ -749,7 +745,6 @@ export default async (app, { getRouter }) => {
await verifyInstallationAnalytics(
context,
repository,
false,
0,
latestCommitInfo,
);
Expand Down
57 changes: 12 additions & 45 deletions bot/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";
import dotenv from "dotenv";
import { MongoClient } from "mongodb";
import fs from "fs";
import { consola } from "consola";
import { nanoid } from "nanoid";

if (process.env.NODE_ENV !== "production") {
dotenv.config({
Expand All @@ -20,7 +19,6 @@ if (!process.env.MONGODB_DB_NAME) {

const uri = process.env.MONGODB_URI;
const dbName = process.env.MONGODB_DB_NAME;
const devDbName = `${dbName}-migrations-test`;

// Create a new MongoClient
const client = new MongoClient(uri);
Expand All @@ -33,45 +31,13 @@ if (!database) {
throw new Error("Database not found");
}

const devDatabase = client.db(devDbName);

// FOR DEV ONLY
// Clone the original database
// Get the list of collections in the original database
consola.start("Cloning the original database...");

const collections = await database.listCollections().toArray();

for (const collection of collections) {
const collectionName = collection.name;

// Get the collection
const dbCollection = database.collection(collectionName);

// Get the documents in the collection
const documents = await dbCollection.find().toArray();

// Drop the collection in the new database if it exists
await devDatabase.dropCollection(collectionName).catch(() => {});

// Create a new collection in the new database
const newCollection = devDatabase.collection(collectionName);

// Insert the documents into the new collection
if (documents.length > 0) {
await newCollection.insertMany(documents);
}
}

consola.success("Database cloned!");

// Get the list of files in the migrations folder
const files = fs.readdirSync("./migrations");

// Order the files by name
files.sort();

const migrationsCollection = devDatabase.collection("migrations");
const migrationsCollection = database.collection("migrations");

for (const file of files) {
// Get the file name without the extension
Expand All @@ -96,19 +62,20 @@ for (const file of files) {

try {
// Run the migration
await migrationFunction(uri, devDbName, migrationId);
const entriesUpdated = await migrationFunction(uri, dbName, migrationId);

consola.success(`Migration ${migrationId} has been applied!`);

// Insert the migration into the migrations collection
await migrationsCollection.insertOne({
created_at: new Date(),
entries_updated: entriesUpdated,
migration_id: migrationId,
});
} catch (error) {
consola.error(`Error applying migration ${migrationId}: ${error.message}`);
throw error;
}

consola.success(`Migration ${migrationId} has been applied!`);

// Insert the migration into the migrations collection
// await migrationsCollection.insertOne({
// migration_id: migrationId,
// created_at: new Date(),
// });
}

await client.close();
Expand Down
Loading
Loading