Skip to content

Feature Request: Per commit modified_files, JSONDiffForFile, fileMatch #1341

Open
@glensc

Description

Describe the feature

Converting #1335 to a feature request

Expected behavior

There are use-cases where you want to analyse files changed by a commit:

  1. you changed package.json but not yarn.lock
  2. you pinned a package and didn't leave commit message body why you pinned.
  3. modified source, but didn't add/update tests

and those per commit, not whole merge request.

therefore would want to have commit.modified_files, commit.JSONDiffForFile, commit.fileMatch methods:

  const packageDiff = await commit.JSONDiffForFile("package.json")

  if (packageDiff.dependencies) {
      const newDependencies = packageDiff.dependencies.added;
      if (newDependencies.includes(blacklist)) {
        fail(`${commit.sha}: Do not add ${blacklist} to our dependencies, see CVE #23`);
      }
  }
  
  const packageJson = commit.fileMatch("package.json");
  const packageLock = commit.fileMatch("yarn.lock");

  if (packageJson.modified && !packageLock.modified) {
    warn("${commit.sha}: This commit modified `package.json`, but not `yarn.lock`");
  }
  
  const testChanges = commit.modified_files.filter(filepath => filepath.match(/(test|cypress)/));
  if (testChanges.length < 1) {
    warn(`${commit.sha}: This commit does not have any changes in automated tests. Please consider adding some tests.`)
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions