|
| 1 | +<% |
| 2 | +
|
| 3 | +var FLAG_PATTERN = /^(Fix|Update|New|Breaking|Build|Docs|Upgrade):/, |
| 4 | + ISSUE_REF_PATTERN = /\((fixes|refs) #\d+.*?\)$/; |
| 5 | +
|
| 6 | +function isValidCommitFlag(log) { |
| 7 | + var result = log.match(FLAG_PATTERN); |
| 8 | + return !!result || log.indexOf("Revert \"") === 0; |
| 9 | +} |
| 10 | +
|
| 11 | +function needsIssueRef(log) { |
| 12 | + var result = log.match(ISSUE_REF_PATTERN); |
| 13 | + return !result && log.indexOf("Docs:") !== 0; |
| 14 | +} |
| 15 | +
|
| 16 | +var problems = []; |
| 17 | +
|
| 18 | +// Check for one commit per pull request |
| 19 | +if (payload.commits > 1) { |
| 20 | + problems.push("We require one commit per pull request. Please [squash](https://egghead.io/lessons/javascript-how-to-squash-multiple-git-commits) your commits."); |
| 21 | +} else if (meta.commits) { |
| 22 | + // get just the first line of the commit message |
| 23 | + var log = meta.commits[0].commit.message.split(/\r?\n/g)[0]; |
| 24 | +
|
| 25 | + if (!isValidCommitFlag(log)) { |
| 26 | + problems.push("The commit summary needs to begin with a tag (such as `Fix:` or `Update:`). Please check out our [guide](http://eslint.org/docs/developer-guide/contributing/pull-requests#step-2-make-your-changes) for how to properly format your commit summary and [update](http://eslint.org/docs/developer-guide/contributing/pull-requests#updating-the-commit-message) it on this pull request.") |
| 27 | + } |
| 28 | +
|
| 29 | + if (log.length > 72) { |
| 30 | + problems.push("The commit summary must be 72 characters or shorter. Please check out our [guide](http://eslint.org/docs/developer-guide/contributing/pull-requests#step-2-make-your-changes) for how to properly format your commit summary and [update](http://eslint.org/docs/developer-guide/contributing/pull-requests#updating-the-commit-message) it on this pull request."); |
| 31 | + } |
| 32 | +
|
| 33 | + if (needsIssueRef(log)) { |
| 34 | + problems.push("Pull requests with code require an issue to be mentioned at the end of the commit summary, such as `(fixes #1234)`. Please [update](http://eslint.org/docs/developer-guide/contributing/pull-requests#updating-the-commit-message) the commit summary with an issue (file a new issue if one doesn't already exist).") |
| 35 | + } |
| 36 | +} |
| 37 | +
|
| 38 | +// Check for CLA signature |
| 39 | +if (!meta.cla) { |
| 40 | + problems.push("Please sign our [CLA](http://eslint.org/cla). This is just a way for you to say that you give us permission to use your contribution.") |
| 41 | +} |
| 42 | +
|
| 43 | +if (problems.length) { %> |
| 44 | +Thanks for the pull request, @<%= payload.sender.login %>! I took a look to make sure it's ready for merging and found some changes are needed: |
| 45 | +
|
| 46 | +<% problems.forEach(function(problem) { %> |
| 47 | +* <%- problem %> |
| 48 | +<% }); %> |
| 49 | +
|
| 50 | +Can you please update the pull request to address these? |
| 51 | +
|
| 52 | +(More information can be found in our [pull request guide](http://eslint.org/docs/developer-guide/contributing/pull-requests).) |
| 53 | +<% } else { %> |
| 54 | +LGTM |
| 55 | +<% } %> |
0 commit comments