Skip to content
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

Check that the change log has been updated as part of a PR #759

Merged
merged 11 commits into from
Mar 15, 2017

Conversation

rpowis
Copy link
Contributor

@rpowis rpowis commented Mar 3, 2017

Problem

Having added a CHANGELOG.md we need a way to remind contributors to update it when they make a pull request.

Solution

Add a gulp task that breaks the build if CHANGELOG.md hasn't been updated as part of the pull request.

  • Get the commit being built
  • Diff the commit against master for the names of the files that have changed
  • Check to see if CHANGELOG.md appears in that list and throw an error if it does

Failing: https://travis-ci.org/hmrc/assets-frontend/builds/207461966#L1140:

image

Passing: https://travis-ci.org/hmrc/assets-frontend/builds/207466855#L1141

image

Copy link
Contributor

@feedmypixel feedmypixel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff @rpowis
A few comments, mainly around self documenting variable names, a few more checks on tests and ways of writingPromise functions.

return Promise.reject(new Error('No CHANGELOG.md update'))
}

return Promise.resolve(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a need to return true here you can just Promise.resolve()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't even be a Promise. See above comment

}

var checkForChangelog = function (files) {
if (!files.includes('CHANGELOG.md')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially a preference thing but I would ask why are you using Promise.reject and Promise.resolve rather than just returning a return new Promise(function (resolve, reject){ ...? It feels like there is a mix of both ways in this file. IMO it would be good to choose one or the other? Feels like a shorthand too far rather than defining this as a Promise at the function/interface level. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is a mix of styles. I just got bored of writing the boilerplate of return new when hammering this out and then forgot to go back and standardise on one. Oops

I disagree with it being "a shorthand too far" though. If anything these returns shouldn't even be Promises (as returning a value from a then callback is fine) but that was blowing up on Travis for some reason so "Promisify all the things" was the quickest/easiest way around it 😕

I'll go back and investigate further. Happy to pair on it if you want?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need to "Promisify all the things" it feels for readability there should be one style

} else {
var cmd = 'git rev-parse HEAD'
runCommand(cmd)
.then(function (commit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can just be .then(resolve)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point

getCurrentCommit(process.env.TRAVIS_COMMIT)
.then(getChangedFiles)
.then(checkForChangelog)
.then(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can just be .then(done)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it can't because it will pass the return value to done(), making gulp think there's an error when there isn't one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that feels a little like if checkForChangelog did this it wouldn't? why does it need to return true? (I suspect something I'm not aware of)

var checkForChangelog = function (files) {
  return new Promise((function (resolve, reject) {
    if (!files.includes('CHANGELOG.md')) {
      reject(new Error('No CHANGELOG.md update'))
   }
   resolve()
})

Copy link
Contributor Author

@rpowis rpowis Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's there is easier to read than that IMO.

It returns true because it has to return something. But really, we should be able to get rid of the Promise entirely as then() returns a promise anyway.


changelog.runCommand()
.catch(function (data) {
t.ok(data instanceof Error, 'returns an Error if the command fails')
Copy link
Contributor

@feedmypixel feedmypixel Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth also checking data.message/err.message here?

})

changelog.runCommand('echo "test"')
.then(function (command) {
Copy link
Contributor

@feedmypixel feedmypixel Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command variable could/should be stdout

var changedFiles = changelog.getChangedFiles('test')

noBranch.catch(function (err) {
t.ok(err instanceof Error, 'throws an error when not given a branch')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also check err.message here?


changelog.checkForChangelog('CHANGELOG')
.catch(function (err) {
t.ok(err instanceof Error, 'returns an Error when CHANGELOG.md cannot be found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also check err.message here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a dupe of the previous comment

getCurrentCommit(process.env.TRAVIS_COMMIT)
.then(getChangedFiles)
.then(checkForChangelog)
.then(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be .then(done)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same comment as above somehow? 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm not sure what has happened there?

@@ -134,6 +134,7 @@
"devDependencies": {
"gulp-standard": "^8.0.3",
"gulp-tape": "0.0.9",
"sinon": "^1.17.7",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this (and all the other dev dependencies) going to cause HMRC prototype kit problems? May be worth moving them to dependencies but as a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter, HMRC Prototype Kit is deprecated. They're not prod dependencies so they're going in devDependencies as they rightly should.

@feedmypixel
Copy link
Contributor

Also this branch needs to rebase master onto it

@rpowis rpowis dismissed feedmypixel’s stale review March 8, 2017 10:08

Made the fixes that needed to be made. The remaining comments have coments

@feedmypixel
Copy link
Contributor

LGTM 👍

@feedmypixel feedmypixel merged commit b3f35e5 into master Mar 15, 2017
@feedmypixel feedmypixel deleted the SDT-207-changelog-check branch March 15, 2017 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants