diff --git a/actions/release-management/actions/comment.js b/actions/release-management/actions/comment.js index 3b3907c..e28a5fb 100644 --- a/actions/release-management/actions/comment.js +++ b/actions/release-management/actions/comment.js @@ -29,14 +29,14 @@ function createAction (serviceLocator) { if (comment.body.indexOf(suffix) === -1) { return cb(null, false) } - // Ignore anything that is the bot commenting with a comment that includes @itself - if (comment.author === serviceLocator.authedUser.username) { - return cb(null, false) - } // If the comment contains a trigger phrase then we are good to go if (checkTriggerPhrase(comment.body)) { return cb(null, true) } + // Ignore anything that is the bot commenting with a comment that includes @itself + if (comment.author === serviceLocator.authedUser.username) { + return cb(null, false) + } // Otherwise, let the user know the command is unknown repoManager.getPull(comment.issueNumber, function (error, pr) { if (error) return cb(error) diff --git a/actions/release-management/test/actions/comment.test.js b/actions/release-management/test/actions/comment.test.js index 55db9b0..f4aaa76 100644 --- a/actions/release-management/test/actions/comment.test.js +++ b/actions/release-management/test/actions/comment.test.js @@ -27,7 +27,7 @@ describe('release-management comment action', function () { }) }) - it('should not pass check comment includes bot and is created by bot', function (done) { + it('should not pass check comment includes bot and is created by bot and contains trigger phrase', function (done) { var sl = { authedUser: { username: 'test' } , repoManager: function () { @@ -35,6 +35,64 @@ describe('release-management comment action', function () { } , action = createAction(sl) action.check('created', { body: '@test add to release', author: 'test' }, function (error, shouldExec) { + if (error) return done(error) + assert.equal(shouldExec, true, 'shouldExec should be true') + done() + }) + }) + + it( + 'should not pass check comment includes bot and is created by bot' + + ' and contains trigger phrase in the middle of comment body' + , function (done) { + var sl = + { authedUser: { username: 'test' } + , repoManager: function () { + } + } + , action = createAction(sl) + action.check( + 'created' + , { body: '@test foobar baz @test merged into release', author: 'test' } + , function (error, shouldExec) { + if (error) return done(error) + assert.equal(shouldExec, false, 'shouldExec should be false') + done() + }) + }) + + it( + 'should not pass check comment includes bot and is created by bot' + + ' and contains trigger phrase in the middle of comment body' + + 'and is the unknown command message' + , function (done) { + var sl = + { authedUser: { username: 'test' } + , repoManager: function () { + } + } + , action = createAction(sl) + action.check( + 'created' + , { body: '@test Unknown command: foobar baz @test merged into release', author: 'test' } + , function (error, shouldExec) { + if (error) return done(error) + assert.equal(shouldExec, false, 'shouldExec should be false') + done() + }) + }) + + it( + 'should not pass check comment includes bot and is created by bot' + + ' and does not contain trigger phrase' + , function (done) { + var sl = + { authedUser: { username: 'test' } + , repoManager: function () { + } + } + , action = createAction(sl) + action.check('created', { body: '@test foobar baz WITH HASTE', author: 'test' }, function (error, shouldExec) { if (error) return done(error) assert.equal(shouldExec, false, 'shouldExec should be false') done() diff --git a/actions/release-management/test/lib/ready-for-production.test.js b/actions/release-management/test/lib/ready-for-production.test.js index f83539d..517df5d 100644 --- a/actions/release-management/test/lib/ready-for-production.test.js +++ b/actions/release-management/test/lib/ready-for-production.test.js @@ -35,7 +35,7 @@ describe('release-management ready for production', function () { , addComment: function (comment, cb) { addCommentCalled = true assert.equal(comment, '@jack This release is already prepared for production.' + - ' If the release failed and you are retrying, remove the `ready-for-production`'+ + ' If the release failed and you are retrying, remove the `ready-for-production`' + ' label and rerun the command.') cb() } diff --git a/actions/release-management/test/lib/ready-for-staging.test.js b/actions/release-management/test/lib/ready-for-staging.test.js index 88c0ee6..3cb5ae3 100644 --- a/actions/release-management/test/lib/ready-for-staging.test.js +++ b/actions/release-management/test/lib/ready-for-staging.test.js @@ -35,7 +35,7 @@ describe('release-management ready for staging', function () { , addComment: function (comment, cb) { addCommentCalled = true assert.equal(comment, '@jack This release is already prepared for staging.' + - ' If the release failed and you are retrying, remove the `ready-for-staging`'+ + ' If the release failed and you are retrying, remove the `ready-for-staging`' + ' label and rerun the command.') cb() }