Skip to content

Commit

Permalink
release-20170718 (#8)
Browse files Browse the repository at this point in the history
* fix logging all commits from develop (instead of just base branch) (#5)

* relax travis check, mini version increase, better error logging, tidy up code (#7)
  • Loading branch information
GrayedFox authored Jul 18, 2017
1 parent fa59b40 commit cc48db0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
45 changes: 30 additions & 15 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,30 @@ const commandHandler = (command) => {
})
}

// Updates the exitCode and logs errors form command promise rejections
// Logs errors from promise rejections, including stack trace
const errorHandler = (error) => {
console.error(error)
process.exit(1)
console.log(error.stack.replace(error.message, ''))
quit(error.message, 1)
}

// Log squashed messages in blue so they stand out
const prettyLog = (message) => {
console.log(`\x1b[34m${message}\x1b[0m`)
// Log pass messages in blue so they stand out, with padding
const logPass = (message) => {
console.log(`
\x1b[34m${message}\x1b[0m
`)
}

// Log fail message in red so they stand out, with padding
const logFail = (message) => {
console.log(`
\x1b[31m${message}\x1b[0m
`)
}

// Quit squashed with a given message and exit code
const quit = (message, statusCode = 0) => {
statusCode === 0 ? logPass(message) : logFail(message)
process.exit(statusCode)
}

// Initialisation and env setup
Expand All @@ -40,7 +55,12 @@ const init = () => {
}

// if run inside Travis CI we need to ensure we update the commitRef since we are working in a detached head state
if (process.env.TRAVIS_PULL_REQUEST_BRANCH) {
if (process.env.TRAVIS) {
if (!process.env.TRAVIS_PULL_REQUEST_SHA) {
quit(`No need to run squashed against push builds!`)
} else if (process.env.TRAVIS_BRANCH !== 'develop') {
quit(`No need to run squashed against pull requests that don't target develop!`)
}
commitRef = process.env.TRAVIS_PULL_REQUEST_SHA
}
console.log(`Commit Reference: ${commitRef}`)
Expand All @@ -51,14 +71,9 @@ init()
Promise.all([commandHandler(`getBranchCommitCount.sh ${commitRef}`), commandHandler(`getFormattedBranchCommits.sh ${commitRef}`)]).then(
([commitCount, formattedBranchCommits]) => {
if (commitCount > 1) {
console.log(`
${formattedBranchCommits}`)
prettyLog(`
You need to squash those ${+commitCount} commits!
`)
process.exit(1)
console.log(`${formattedBranchCommits}`)
quit(`You need to squash those ${+commitCount} commits!`, 1)
} else {
prettyLog('Merge away McLoven :)')
process.exit(0)
quit(`Merge away McLoven :)`)
}
}, errorHandler)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "squashed",
"version": "1.1.2",
"version": "1.1.22",
"description": "A nifty tool to check if your branch needs to be rebased/squashed",
"main": "app.js",
"bin": {
Expand Down

0 comments on commit cc48db0

Please sign in to comment.