From daced2a9fd4f4a1988639f464d0899c32f5bda42 Mon Sep 17 00:00:00 2001 From: Sanjay Soundarajan Date: Fri, 9 Aug 2024 16:16:54 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20feat:=20add=20metrics=20for=20ui?= =?UTF-8?q?=20side?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codeMetadata/[identifier]/index.post.ts | 67 +++++++++++++++++++ .../cwlValidation/[identifier]/rerun.post.ts | 38 +++++++++++ .../api/license/[identifier]/index.post.ts | 58 ++++++++++------ 3 files changed, 142 insertions(+), 21 deletions(-) diff --git a/ui/server/api/codeMetadata/[identifier]/index.post.ts b/ui/server/api/codeMetadata/[identifier]/index.post.ts index a9501e54..0cfe410b 100644 --- a/ui/server/api/codeMetadata/[identifier]/index.post.ts +++ b/ui/server/api/codeMetadata/[identifier]/index.post.ts @@ -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, diff --git a/ui/server/api/cwlValidation/[identifier]/rerun.post.ts b/ui/server/api/cwlValidation/[identifier]/rerun.post.ts index 0af4d3ea..4dc2c264 100644 --- a/ui/server/api/cwlValidation/[identifier]/rerun.post.ts +++ b/ui/server/api/cwlValidation/[identifier]/rerun.post.ts @@ -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", }; diff --git a/ui/server/api/license/[identifier]/index.post.ts b/ui/server/api/license/[identifier]/index.post.ts index 9e8e5f53..55df227f 100644 --- a/ui/server/api/license/[identifier]/index.post.ts +++ b/ui/server/api/license/[identifier]/index.post.ts @@ -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,