Skip to content

Commit

Permalink
Update CHANGELOG tutorial to use fileMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Mar 22, 2022
1 parent 7cf6c03 commit 4724d2b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions docs/tutorials/node-library.html.md
Expand Up @@ -20,28 +20,24 @@ check that a CHANGELOG entry is added on every PR:

```js
import { danger, fail, warn } from "danger"
import includes from "lodash.includes"

const hasCHANGELOGChanges = includes(danger.git.modified_files, "CHANGELOG.md")
if (!hasCHANGELOGChanges) {
const changelogChanges = danger.git.fileMatch("CHANGELOG.md")
if (!changelogChanges.modified) {
warn("This pull request may need a CHANGELOG entry.")
}
```

We're using lodash's `_.include` function to check if `CHANGELOG.md` is in the list of modified files.

We went with `warn` here because there are a lot of legitimate reasons to not need a CHANGELOG entry (updating typoes,
CI and other infrastructure.) We can improve this though, let's _also_ check that there are changes to the source code
for our library.
We went with `warn` here because there are a lot of legitimate reasons to not need a CHANGELOG entry (updating typos, CI
and other infrastructure.) We can improve this though, let's _also_ check that there are changes to the source code for
our library.

```js
import { danger, fail, warn } from "danger"
import includes from "lodash.includes"
import first from "lodash.first"

const hasCHANGELOGChanges = includes(danger.git.modified_files, "CHANGELOG.md")
const changelogChanges = danger.git.fileMatch("CHANGELOG.md")
const hasLibraryChanges = first(danger.git.modified_files, path => path.startsWith("lib/"))
if (hasLibraryChanges && !hasCHANGELOGChanges) {
if (hasLibraryChanges && !changelogChanges.modified) {
warn("This pull request may need a CHANGELOG entry.")
}
```
Expand Down

0 comments on commit 4724d2b

Please sign in to comment.