Open
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:
- you changed package.json but not yarn.lock
- you pinned a package and didn't leave commit message body why you pinned.
- 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