-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const {danger, warn, fail, message} = require('danger'); | ||
|
||
if (danger.github && danger.github.pr) { | ||
const commitizenRegex = /^(feat|fix|chore|test|docs|perf|refactor|revert)(\(.*\))?:(.+)$/; | ||
const ghCommits = danger.github.commits; | ||
let willTriggerRelease = false; | ||
for (const {commit} of ghCommits) { | ||
const {message, url} = commit; | ||
const firstLine = message.split('\n')[0]; | ||
|
||
if (message.startsWith('feat') || message.startsWith('fix')) { | ||
willTriggerRelease = true; | ||
} | ||
|
||
const regexMatch = commitizenRegex.exec(firstLine); | ||
if (!regexMatch) { | ||
fail(`Commit ["${firstLine}"](${url}) is not a valid commitizen message. See [Contributing page](https://github.com/snyk/snyk/blob/master/.github/CONTRIBUTING.md#commit-types) with required commit message format.`); | ||
} | ||
|
||
if (firstLine.length >= 72) { | ||
warn(`Your commit message ["${firstLine}"](${url}) is too long. Keep first line of your commit under 72 characters.`); | ||
} | ||
} | ||
|
||
if (!willTriggerRelease) { | ||
message('This PR will not trigger a new version. It doesn\'t include any commit message with `feat` or `fix`.'); | ||
} | ||
} |