Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 678db53

Browse files
Merge pull request #57 from codiga/feat/add-rule-metrics
feat: add records for Codiga file and rule fix uses
2 parents 08bcfad + f733f4e commit 678db53

7 files changed

Lines changed: 60 additions & 2 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"React",
3232
"Typescript"
3333
],
34-
"version": "0.8.8",
34+
"version": "0.8.9",
3535
"engines": {
3636
"vscode": "^1.70.0"
3737
},
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { getUserFingerprint } from "../utils/configurationUtils";
2+
import { doMutation } from "./client";
3+
import { USE_CREATE_CODIGA_YAML } from "./mutations";
4+
5+
/**
6+
* creates a record when the user creates a codiga.yml file through
7+
* our VSCode suggestion popup
8+
*/
9+
export async function addCreateCodigaYamlRecord(): Promise<void> {
10+
// Get the fingerprint from localstorage to initiate the request
11+
const userFingerprint = getUserFingerprint();
12+
13+
// record that a rule fix has taken place
14+
await doMutation(USE_CREATE_CODIGA_YAML, {
15+
fingerprint: userFingerprint,
16+
});
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getUserFingerprint } from "../utils/configurationUtils";
2+
import { doMutation } from "./client";
3+
import { USE_RULE_FIX } from "./mutations";
4+
5+
/**
6+
* creates a record when a rule fix was applied in the editor
7+
*/
8+
export async function addRuleFixRecord(): Promise<void> {
9+
// Get the fingerprint from localstorage to initiate the request
10+
const userFingerprint = getUserFingerprint();
11+
12+
// record that a rule fix has taken place
13+
await doMutation(USE_RULE_FIX, {
14+
fingerprint: userFingerprint,
15+
});
16+
}

src/graphql-api/mutations.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,24 @@ export const USE_RECIPE: string = gql`
1010
)
1111
}
1212
`;
13+
14+
export const USE_RULE_FIX: string = gql`
15+
mutation recordAccess($fingerprint: String, $ruleId: Long) {
16+
recordAccess(
17+
accessType: VsCode
18+
actionType: RuleFix
19+
ruleId: $ruleId
20+
userFingerprint: $fingerprint
21+
)
22+
}
23+
`;
24+
25+
export const USE_CREATE_CODIGA_YAML: string = gql`
26+
mutation recordAccess($fingerprint: String) {
27+
recordAccess(
28+
accessType: VsCode
29+
actionType: CreateCodigaYaml
30+
userFingerprint: $fingerprint
31+
)
32+
}
33+
`;

src/rosie/rosiefix.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { getFixesForDocument } from "../diagnostics/diagnostics";
3+
import { addRuleFixRecord } from "../graphql-api/add-rule-fix-record";
34
import { RosieFix, RosieFixEdit } from "./rosieTypes";
45

56
/**
@@ -59,6 +60,7 @@ export const applyFix = async (
5960
const workspaceEdit = new vscode.WorkspaceEdit();
6061
workspaceEdit.set(document.uri, edits);
6162
await vscode.workspace.applyEdit(workspaceEdit);
63+
await addRuleFixRecord();
6264
};
6365

6466
export class RosieFixAction implements vscode.CodeActionProvider {

src/utils/startupUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
INFO_MESSAGE_CODIGA_FILE_KEY,
99
VALUE_STRING_TRUE,
1010
} from "../constants";
11+
import { addCreateCodigaYamlRecord } from "../graphql-api/add-create-codiga-yaml-record";
1112
import { isRosieLanguageDetected } from "../rosie/rosieUtils";
1213
import getFileUri, { doesFileExist } from "./fileUtils";
1314
import { getFromLocalStorage, setToLocalStorage } from "./localStorage";
@@ -43,6 +44,7 @@ export async function checkCodigaFileSuggestion() {
4344
"utf-8"
4445
);
4546
await vscode.workspace.fs.writeFile(codigaUri, codigaFileContent);
47+
await addCreateCodigaYamlRecord();
4648
}
4749
}
4850
if (selectedItem === INFO_MESSAGE_CODIGA_FILE_ACTION_IGNORE) {

0 commit comments

Comments
 (0)