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

chore: unify logic for metrics collection when any command is executed #8

Merged
merged 8 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ export default class Bundle extends Command {
this.log(`Check out your shiny new bundled files at ${output}`);
}

const result = await load(output);

// Metrics recording.
await this.recordActionExecuted('bundle', {success: true, files: AsyncAPIFiles.length}, result.text());
this.specFile = await load(output);
this.metricsMetadata = {success: true, files: AsyncAPIFiles.length};
peter-rr marked this conversation as resolved.
Show resolved Hide resolved
}

async loadFiles(filepaths: string[]): Promise<Specification[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{ name: 'spec-file', description: 'spec path, url, or context-name', required: false },
];

async run() {

Check warning on line 31 in src/commands/convert.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed
const { args, flags } = await this.parse(Convert);
const filePath = args['spec-file'];
let specFile;
Expand Down Expand Up @@ -78,13 +78,13 @@
if (document !== undefined) {
metadata = MetadataFromDocument(document, metadata);
metadata['from_version'] = document.version();
this.specFile = await load(filePath);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about this extra parsing stuff here. Would it make sense to use the original file (specFile var) instead 🤔

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, we can revisit all of that in the general PR.

this.metricsMetadata = metadata;
}
} catch (e: any) {
if (e instanceof Error) {
this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`);
}
}

await this.recordActionExecuted('convert', metadata);
}
}
3 changes: 2 additions & 1 deletion src/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export default class Template extends Command {
}

// Metrics recording.
await this.recordActionExecuted('generate_from_template', {success: true, template}, asyncapiInput.text());
this.specFile = asyncapiInput;
this.metricsMetadata = {success: true, template};
}

private parseFlags(disableHooks?: string[], params?: string[], mapBaseUrl?: string): ParsedFlags {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export default class Optimize extends Command {
}

// Metrics recording.
await this.recordActionExecuted('optimize', {success: true, optimizations: this.optimizations}, specFile.text());
this.specFile = await load(filePath);
this.metricsMetadata = {success: true, optimizations: this.optimizations};
}

private showOptimizations(elements: ReportElement[] | undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Flags } from '@oclif/core';

import Command from '../base';
import { validate, validationFlags } from '../parser';
import { load } from '../models/SpecificationFile';
Expand Down Expand Up @@ -32,6 +31,7 @@ export default class Validate extends Command {
const result = await validate(this, specFile, flags);

// Metrics recording.
await this.recordActionExecuted('validate', {success: true, validation_result: result}, specFile.text());
this.specFile = await load(filePath);
this.metricsMetadata = {success: true, validation_result: result};
}
}
Loading