-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Changed changelog linting to check the pull request title #704
test: Changed changelog linting to check the pull request title #704
Conversation
@kumar303 This pull request currently contains an "invalid pull request title" on purpose, so that we can test that the related travis build fails, and then we can change the title and force a rebuild to test that it passes when the pull request title follows the conventions correctly. |
@kumar303 Here is a link to the expected failure: https://travis-ci.org/mozilla/web-ext/jobs/186182234#L1601-L1634 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I feel like one day we should move all grunt scripts to plain on npm run scripts but, hey, that day might never come.
I requested some minor changes and I also think you'll need to incorporate the logic from #701 (comment) if it's not too tricky.
|
||
before_script: | ||
# If this command fails and you can't fix it, file an issue and add an exception to .nsprc | ||
- npm run nsp-check | ||
|
||
script: | ||
- COVERAGE=y NODE_ENV=production npm test | ||
- npm run changelog-lint | ||
- npm run travis-pullrequest-title-lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about github-pr-title-lint
?
pullRequestURLPath | ||
); | ||
|
||
require('https').get({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move this require to the top of the file?
done(false); | ||
}); | ||
response.on('end', function() { | ||
var parsed = JSON.parse(body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good to start the promise chain with this wrapped in new Promise(function(resolve) { ... })
just in case it throws a SyntaxError
. Otherwise, the grunt task might hang.
It would be nice to get a more readable report of errors, if possible. The standard changelog lint output is already pretty confusing to contributors though. Perhaps this should also include a link to the formatting guide ? |
@kumar303 Here is the new failure messages (formatted as the cli tool does and with a nice message added, which links to the "Writing commit messages" section in the CONTRIBUTING.md docs): The name of the task is still I opted to move the new task into its own file, it looks like "a good time to move some complex tasks into their own file" can be now after all ;-) I also changed the task so that it is going to lint the commit message if the branch is composed from a single commit. Let me know how it looks to you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Most nits but I was also unsure about the template string.
@@ -13,7 +13,7 @@ module.exports = function(grunt) { | |||
|
|||
var configs = require('load-grunt-configs')(grunt, { | |||
config: { | |||
src: 'tasks/*.js', | |||
src: 'tasks/configs/*.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. The helper comment needs updating too: https://github.com/rpl/web-ext/blob/2e95f3dd3db4df77177c8a459965d61831860425/Gruntfile.js#L8
function getPullRequestTitle() { | ||
return new Promise(function(resolve, reject) { | ||
var pullRequestURLPath = `/repos/${ process.env.TRAVIS_REPO_SLUG | ||
}${/pulls/ }${process.env.TRAVIS_PULL_REQUEST }.json`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to use a template string here? I'm surprised this works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch, it shouldn't be there, I tried to remove any ES6 syntax to keep it "ES5"-safe :-)
but I forgot a bunch of them (but it looks like template strings are supported in node >= 4).
removed in the updated pull request.
function getPullRequestTitle() { | ||
return new Promise(function(resolve, reject) { | ||
var pullRequestURLPath = `/repos/${ process.env.TRAVIS_REPO_SLUG | ||
}${/pulls/ }${process.env.TRAVIS_PULL_REQUEST }.json`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I find these easier to read when broken with plus signs (but I know it's not pretty either way):
var pullRequestURLPath = '/repos/' +
`${process.env.TRAVIS_REPO_SLUG}${/pulls/}` +
`${process.env.TRAVIS_PULL_REQUEST }.json`;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is ${/pulls/}
correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't, and it is very interesting that it worked (and it didn't raise any linting error)
I rewrote all the template strings into strings composition, but I will take another look on this (at least to prevent this kind of weird but working template strings to slip in a patch unnoticed in the future ;-)).
} | ||
|
||
var writeCommitMessagesDocURL = | ||
'https://github.com/mozilla/web-ext/blob/master/CONTRIBUTING.md#writing-commit-messages'; // eslint-disable-line max-len |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we've been doing two spaces for any indent, regardless of the type of block continuation. I know some editors do these breaks with more spaces by default (mine does).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this will be definitely in a chapter of my book "when your editor auto-indentation feature works against you" :-D
when I moved all the grunt task code into a separate file, the "auto-indentation on copy & paste" feature decided to mess up my manual indentation :-|
if (commitsCount === 1) { | ||
grunt.log.writeln( | ||
'There is only one commit in this pull request, ' + | ||
'we are going to check the single commit message...' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typically we've been indenting breaks like this at the same level since it's not a nested block, it's a continuation of the block on the previous line
'There is more than one commit in this pull request, ' + | ||
'we are going to check the pull request title...' | ||
); | ||
return getPullRequestTitle().then(lintMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like .then(lintMessage)
is the same for both cases so it can be moved down into the promise chain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
); | ||
|
||
grunt.log.writeln( | ||
`${'\nDon\'t panic! If your travis build is failing here, ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this message!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehehe, I knew you would like it!
'please take a look at \n\n' + | ||
' - '}${ writeCommitMessagesDocURL }\n\n` + | ||
'and/or mention in a comment one of the mantainers, ' + | ||
'we are here to help ;-)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could just say:
Please take a look at [link] and feel free to ask for help from one of the maintainers in a comment; we are here to help ;-)
I'm suggesting that because they may not know what usernames to mention and I think we are pretty good about reading all comments anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
message tweaked in the last pushed update!
@kumar303 The last push build passed, and it shouldn't until we change the pull request title. do not merge this pull request yet, I'm looking into it |
fc0ad41
to
e1d06d5
Compare
e1d06d5
to
acbc022
Compare
@kumar303 I tweaked the grunt task a bit:
I've not yet removed the .githooks dir because it seems to me that, on a local dev environment of a contributor where the git hooks are already installed, the raised error message (the one that would be raised if the .githooks dir is missing) can be confusing, and so it is probably better to defer their removal (but in the meantime it is reasonable that we do not auto-install the git hooks anymore). I played a bit with this branch by rebuilding it on travis multiple times, with and without changing the title, Once the travis build is green, it should be ready, let me know how it looks to you. |
@kumar303 I updated the CONTRIBUTING.md file so that it mentions that the pull requests subject is checked using the same approach used for the commit messages (The new changelog linting task actually checks the commit messages only when there is only one commit in the pull request, but I preferred to keep it simple and don't mention this behavior in the CONTRIBUTING.md change). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, is it ready to merge? If so, merge it in!
Here's one idea about the .githooks
. What if you keep the scripts there but make them do nothing? They could also print "This commit hook is no longer needed, you can safely remove it." At the very least, this patch should probably add a comment in each hook script about the change.
👍 sounds great to me! I applied it in 63b55a5 |
This pull request contains an attempt to implement a better changelog linting by running conventiona-changelog-lint on the pull request title instead of running it on the the commit messages, especially given that the single commits are going to be squashed when the pull request is merged, while the pull request title is what becomes the new commit message and it wasn't currently linted using conventional-changelog-lint, until it reaches master (which means... too late :-))
Fixes #701