This repository has been archived by the owner on Mar 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathcodechecks.js
55 lines (48 loc) · 1.67 KB
/
codechecks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { join } = require("path");
const fs = require("fs");
const { codechecks } = require("@codechecks/client");
const CodeChecksReport = require("eth-gas-reporter/lib/codechecksReport");
/**
* Consumed by codecheck command when user's .yml lists
* `eth-gas-reporter/codechecks`. The reporter dumps collected
* data to the project root whenever `process.env.CI` is true. This
* file processes it and runs the relevant codechecks routines.
* >
* > Source: krzkaczor/truffle-codechecks.
* >
*/
module.exports.default = async function gasReporter() {
let output;
let file = "gasReporterOutput.json";
// Load gas reporter output
try {
output = JSON.parse(fs.readFileSync(file, "utf-8"));
} catch (error) {
const message =
`Error: Couldn't load data from "${file}".\n` +
`If you're using codechecks locally make sure you set ` +
`the environment variable "CI" to "true" before running ` +
`your tests. ( ex: CI=true npm test )`;
console.err(message);
return;
}
// Save new data on the merge commit / push build
if (!codechecks.isPr()) {
const report = new CodeChecksReport(output.config);
report.generate(output.info);
await codechecks.saveValue(output.namespace, report.newData);
return;
}
// Get historical data for each pr commit
output.config.previousData =
(await codechecks.getValue(output.namespace)) || null;
const report = new CodeChecksReport(output.config);
const table = report.generate(output.info);
const shortDescription = report.getShortDescription();
// Submit report
await codechecks.success({
name: "Gas Usage",
shortDescription: shortDescription,
longDescription: table
});
};