-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix the bot commenting on edits more than once #13294
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,34 @@ module.exports = function(robot, alexa) { | |
|
||
if (problems.length === 0) { | ||
// User submission is OK | ||
const params = context.issue({body: 'Thanks! Your edit helped me out. I\'ll take it from here now.'}); | ||
|
||
let commentedBefore = false; | ||
|
||
// This won't work if the bot comments success past 100 comments | ||
// but since this will probably never happen, who cares. Also, | ||
// the bot was originally put into production late September, so | ||
// only ask for comments after then. | ||
// | ||
// XXX handle the user screwing up, then fixing it (and getting | ||
// the success comment), then screwing up again | ||
const _allComments = await context.github.issues.getComments(context.issue({ | ||
per_page: 100, // eslint-disable-line camelcase | ||
since: '2017-09-25' | ||
})); | ||
const allComments = _allComments.data; | ||
|
||
allComments.forEach(comment => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// 'Your edit helped me out' is here to match legacy comments | ||
// before this conditional was put in place | ||
if (comment.body.includes('HELPED_COMMENT_POSTED') | ||
|| comment.body.includes('Your edit helped me out')) { | ||
commentedBefore = true; | ||
} | ||
}); | ||
|
||
if (commentedBefore) return; | ||
|
||
const params = context.issue({body: 'Thanks! Your edit helped me out. I\'ll take it from here now. <!-- HELPED_COMMENT_POSTED -->'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @koops76 what's the difference, besides the quotes? I've consistently been using single quotes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok to use double quotes to avoid escaping |
||
await context.github.issues.createComment(params); | ||
|
||
return labeler(context, data, alexa); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ module.exports = { | |
github: { | ||
issues: { | ||
createComment: sinon.spy(), | ||
// TODO actually make this keep track of data | ||
getComments: function() { | ||
return { | ||
data: [] | ||
}; | ||
}, | ||
addLabels: sinon.spy(), | ||
removeLabel: sinon.spy(() => new Promise(noop)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
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.
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 did this originally but decided the other way made what was happening clearer. Your version is super dense :)
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.
At least call it
allCommentsData
instead of the same name but without an underscore.