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

📈 feat: add metrics for ui side #52

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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