-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from danger/package-json-yarn-lock-warning
Warn if changes to package.json and not yarn.lock
- Loading branch information
Showing
1 changed file
with
13 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
// import { danger, warn } from "danger" | ||
import fs from "fs" | ||
import includes from "lodash.includes" | ||
|
||
// Request a CHANGELOG entry if not declared #trivial | ||
const hasChangelog = danger.git.modified_files.includes("changelog.md") | ||
const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes("#trivial") | ||
const hasChangelog = includes(danger.git.modified_files, "changelog.md") | ||
const isTrivial = includes((danger.github.pr.body + danger.github.pr.title), "#trivial") | ||
if (!hasChangelog && !isTrivial) { | ||
warn("Please add a changelog entry for your changes.") | ||
|
||
// Politely ask for their name on the entry too | ||
const changelogDiff = danger.git.diffForFile("changelog.md") | ||
const contributorName = danger.github.pr.user.login | ||
if (changelogDiff && changelogDiff.indexOf(contributorName) === -1) { | ||
if (changelogDiff && !includes(changelogDiff, contributorName)) { | ||
warn("Please add your GitHub name to the changelog entry, so we can attribute you.") | ||
} | ||
} | ||
|
||
// Warns if there are changes to package.json without changes to yarn.lock. | ||
const packageChanged = includes(danger.git.modified_files, "package.json") | ||
const lockfileChanged = includes(danger.git.modified_files, "yarn.lock") | ||
if (packageChanged && !lockfileChanged) { | ||
const message = "Changes were made to package.json, but not to yarn.lock" | ||
const idea = "Perhaps you need to run `yarn install`?" | ||
warn(`${message} - <i>${idea}</i>`) | ||
} |