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

fix: bot should listen to comments created by itself except when it shouldnt #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions actions/release-management/actions/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 59 additions & 1 deletion actions/release-management/test/actions/comment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,72 @@ 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 () {
}
}
, 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down