Feature Request: Per commit modified_files, JSONDiffForFile, fileMatch
- Dominant language
- TypeScript
- Stars
- 5.5k
- Forks
- 379
- Avg merge
- 2h 8m
- Merged PRs (30d)
- 6
Description
**Describe the feature**
Converting https://github.com/danger/danger-js/discussions/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:
```ts
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.`)
}
```
Contributor guide
Research direction
Start by reviewing discussion #1335 and the usage examples in this issue, then trace how per-commit data is currently exposed. Define the scope and completion criteria for modified_files, JSONDiffForFile, and fileMatch, including their behavior for the package and test-change cases; no files or tests are named in the payload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100