How to use @codechecks/client - 10 common examples

To help you get started, we’ve selected a few @codechecks/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cgewecke / eth-gas-reporter / codechecks.js View on Github external
`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.log(message);
    return;
  }

  // Lets monorepo subcomponents individuate themselves
  output.namespace = options.name
    ? `${output.namespace}:${options.name}`
    : output.namespace;

  // Save new data on the merge commit / push build
  if (!codechecks.isPr()) {
    const report = new CodeChecksReport(output.config);
    report.generate(output.info);

    try {
      await codechecks.saveValue(output.namespace, report.newData);
      console.log(`Successful save: output.namespace was: ${output.namespace}`);
    } catch (err) {
      console.log(
        `If you have a chance, report this incident to the eth-gas-reporter github issues.`
      );
      console.log(`Codechecks errored running 'saveValue'...\n${err}\n`);
      console.log(`output.namespace was: ${output.namespace}`);
      console.log(`Saved gas-reporter data was: ${report.newData}`);
    }

    return;
github cgewecke / eth-gas-reporter / codechecks.js View on Github external
output.config.previousData = await codechecks.getValue(output.namespace);
  } catch (err) {
    console.log(
      `If you have a chance, report this incident to the eth-gas-reporter github issues.`
    );
    console.log(`Codechecks errored running 'getValue'...\n${err}\n`);
    return;
  }

  const report = new CodeChecksReport(output.config);
  const table = report.generate(output.info);
  const shortDescription = report.getShortDescription();

  // Submit report
  try {
    await codechecks.success({
      name: "Gas Usage",
      shortDescription: shortDescription,
      longDescription: table
    });
  } catch (err) {
    console.log(
      `If you have a chance, report this incident to the eth-gas-reporter github issues.`
    );
    console.log(`Codechecks errored running 'success'...\n${err}\n`);
    console.log(`Short description was: ${shortDescription}`);
    console.log(`Table was: ${table}`);
  }
};
github cgewecke / eth-gas-reporter / codechecks.js View on Github external
console.log(`Successful save: output.namespace was: ${output.namespace}`);
    } catch (err) {
      console.log(
        `If you have a chance, report this incident to the eth-gas-reporter github issues.`
      );
      console.log(`Codechecks errored running 'saveValue'...\n${err}\n`);
      console.log(`output.namespace was: ${output.namespace}`);
      console.log(`Saved gas-reporter data was: ${report.newData}`);
    }

    return;
  }

  // Get historical data for each pr commit
  try {
    output.config.previousData = await codechecks.getValue(output.namespace);
  } catch (err) {
    console.log(
      `If you have a chance, report this incident to the eth-gas-reporter github issues.`
    );
    console.log(`Codechecks errored running 'getValue'...\n${err}\n`);
    return;
  }

  const report = new CodeChecksReport(output.config);
  const table = report.generate(output.info);
  const shortDescription = report.getShortDescription();

  // Submit report
  try {
    await codechecks.success({
      name: "Gas Usage",
github cgewecke / eth-gas-reporter / codechecks.js View on Github external
console.log(message);
    return;
  }

  // Lets monorepo subcomponents individuate themselves
  output.namespace = options.name
    ? `${output.namespace}:${options.name}`
    : output.namespace;

  // Save new data on the merge commit / push build
  if (!codechecks.isPr()) {
    const report = new CodeChecksReport(output.config);
    report.generate(output.info);

    try {
      await codechecks.saveValue(output.namespace, report.newData);
      console.log(`Successful save: output.namespace was: ${output.namespace}`);
    } catch (err) {
      console.log(
        `If you have a chance, report this incident to the eth-gas-reporter github issues.`
      );
      console.log(`Codechecks errored running 'saveValue'...\n${err}\n`);
      console.log(`output.namespace was: ${output.namespace}`);
      console.log(`Saved gas-reporter data was: ${report.newData}`);
    }

    return;
  }

  // Get historical data for each pr commit
  try {
    output.config.previousData = await codechecks.getValue(output.namespace);
github codechecks / build-size-watcher / src / __tests__ / index.spec.ts View on Github external
describe("build-size", () => {
  const codeChecksMock = require("../__mocks__/@codechecks/client").codechecks as Mocked<
    typeof codechecks
  >;
  beforeEach(() => jest.resetAllMocks());

  it("should work not in PR context", async () => {
    codeChecksMock.isPr.mockReturnValue(false);
    mockFS({
      [join(__dirname, "../build")]: {
        "main.12315123.js": "APP JS",
        "vendor.123124.js": "VENDOR JS",
        "vendor.12466345.css": "VENDOR CSS",
      },
    });

    await buildSizeWatcher({
      files: [
github nestjs / nest / tools / benchmarks / check-benchmarks.ts View on Github external
export default async function checkBenchmarks() {
  const currentBenchmarks = await getBenchmarks();
  await codechecks.saveValue(benchmarksKey, currentBenchmarks);

  if (!codechecks.isPr()) {
    return;
  }
  const baselineBenchmarks = await codechecks.getValue(
    benchmarksKey,
  );
  const report = getCodechecksReport(currentBenchmarks, baselineBenchmarks);
  await codechecks.report(report);
}
github codechecks / build-size-watcher / src / index.ts View on Github external
const sizes = await Promise.all(matches.map(match => getSize(join(cwd, match), options.gzip)));
    const overallSize = sizes.reduce((a, b) => a + b, 0);

    const artifact: FileArtifact = {
      path: file.path,
      files: matches.length,
      overallSize,
    };

    fullArtifact[file.path] = artifact;
  }

  await codechecks.saveValue(options.artifactName, fullArtifact);

  if (!codechecks.isPr()) {
    return;
  }

  const baseArtifact = await codechecks.getValue(options.artifactName);

  const diff = getArtifactDiff(fullArtifact, baseArtifact);

  const report = getReportFromDiff(diff, options.files, options);
  await codechecks.report(report);
}