Skip to content

Commit

Permalink
📈 feat: add metrics for ui side (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
megasanjay authored Aug 9, 2024
1 parent 1225839 commit b2ec880
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 21 deletions.
67 changes: 67 additions & 0 deletions ui/server/api/codeMetadata/[identifier]/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,73 @@ export default defineEventHandler(async (event) => {
},
);

// Update the analytics data for the repository
const analytics = db.collection("analytics");

// Get the existing analytics data for the repository
const existingAnalytics = await analytics.findOne({
repositoryId: codeMetadataRequest.repositoryId,
});

// Check if the codemeta analytics data exists
if (existingAnalytics?.codeMetadata?.codemeta?.updateCodemeta) {
await analytics.updateOne(
{
repositoryId: codeMetadataRequest.repositoryId,
},
{
$inc: {
"codeMetadata.codemeta.updateCodemeta": 1,
},
},
);
} else {
await analytics.updateOne(
{
repositoryId: codeMetadataRequest.repositoryId,
},
{
$set: {
"codeMetadata.codemeta": {
updateCodemeta: 1,
},
},
},
{
upsert: true,
},
);
}

if (existingAnalytics?.codeMetadata?.citationCFF?.updateCitationCFF) {
await analytics.updateOne(
{
repositoryId: codeMetadataRequest.repositoryId,
},
{
$inc: {
"codeMetadata.citationCFF.updateCitationCFF": 1,
},
},
);
} else {
await analytics.updateOne(
{
repositoryId: codeMetadataRequest.repositoryId,
},
{
$set: {
"codeMetadata.citationCFF": {
updateCitationCFF: 1,
},
},
},
{
upsert: true,
},
);
}

return {
message: "Code metadata request updated successfully",
prUrl: pullRequestData.html_url,
Expand Down
38 changes: 38 additions & 0 deletions ui/server/api/cwlValidation/[identifier]/rerun.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,44 @@ export default defineEventHandler(async (event) => {
});
}

// Update the analytics data for the repository
const analytics = db.collection("analytics");

// Get the existing analytics data for the repository
const existingAnalytics = await analytics.findOne({
repositoryId: cwlValidationRequest.repositoryId,
});

// Check if the codemeta analytics data exists
if (existingAnalytics?.cwlValidation?.rerunCwlValidation) {
await analytics.updateOne(
{
repositoryId: cwlValidationRequest.repositoryId,
},
{
$inc: {
"cwlValidation.rerunCwlValidation": 1,
},
},
);
} else {
await analytics.updateOne(
{
repositoryId: cwlValidationRequest.repositoryId,
},
{
$set: {
cwlValidation: {
rerunCwlValidation: 1,
},
},
},
{
upsert: true,
},
);
}

return {
message: "Request for re-run of CWL validation submitted",
};
Expand Down
58 changes: 37 additions & 21 deletions ui/server/api/license/[identifier]/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,43 @@ export default defineEventHandler(async (event) => {
},
);

/**
* ? Should we close the license request here? Or should we wait for the PR to be merged?
*/

// const closeLicenseRequest = await collection.updateOne(
// {
// identifier,
// },
// {
// $set: {
// open: false,
// },
// },
// );

// if (!closeLicenseRequest) {
// throw createError({
// statusCode: 500,
// statusMessage: "license-request-not-closed",
// });
// }
// Update the analytics data for the repository
const analytics = db.collection("analytics");

// Get the existing analytics data for the repository
const existingAnalytics = await analytics.findOne({
repositoryId: licenseRequest.repositoryId,
});

// Check if the license analytics data exists
if (existingAnalytics?.license?.createLicense) {
await analytics.updateOne(
{
repositoryId: licenseRequest.repositoryId,
},
{
$inc: {
"license.createLicense": 1,
},
},
);
} else {
await analytics.updateOne(
{
repositoryId: licenseRequest.repositoryId,
},
{
$set: {
license: {
createLicense: 1,
},
},
},
{
upsert: true,
},
);
}

return {
prUrl: pullRequestData.html_url,
Expand Down

0 comments on commit b2ec880

Please sign in to comment.