Skip to content

Commit 3de08cb

Browse files
strugeeHainish
authored andcommitted
Fix the bot commenting on edits more than once (EFForg#13294)
Note: this does the *bare minimum* to make tests pass. This change has no real test coverage, but this bug is causing real pain and I _did_ test it manually in production so it'll have to do for now. Fixes EFForg#12855
1 parent d264aad commit 3de08cb

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

utils/issue-format-bot/lib/issueedit.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,34 @@ module.exports = function(robot, alexa) {
4848

4949
if (problems.length === 0) {
5050
// User submission is OK
51-
const params = context.issue({body: 'Thanks! Your edit helped me out. I\'ll take it from here now.'});
51+
52+
let commentedBefore = false;
53+
54+
// This won't work if the bot comments success past 100 comments
55+
// but since this will probably never happen, who cares. Also,
56+
// the bot was originally put into production late September, so
57+
// only ask for comments after then.
58+
//
59+
// XXX handle the user screwing up, then fixing it (and getting
60+
// the success comment), then screwing up again
61+
const _allComments = await context.github.issues.getComments(context.issue({
62+
per_page: 100, // eslint-disable-line camelcase
63+
since: '2017-09-25'
64+
}));
65+
const allComments = _allComments.data;
66+
67+
allComments.forEach(comment => {
68+
// 'Your edit helped me out' is here to match legacy comments
69+
// before this conditional was put in place
70+
if (comment.body.includes('HELPED_COMMENT_POSTED')
71+
|| comment.body.includes('Your edit helped me out')) {
72+
commentedBefore = true;
73+
}
74+
});
75+
76+
if (commentedBefore) return;
77+
78+
const params = context.issue({body: 'Thanks! Your edit helped me out. I\'ll take it from here now. <!-- HELPED_COMMENT_POSTED -->'});
5279
await context.github.issues.createComment(params);
5380

5481
return labeler(context, data, alexa);

utils/issue-format-bot/test/issueedit-handler-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
const vows = require('perjury'),
66
handlerutil = require('./lib/handlerutil');
77

8+
// TODO make this test that the bot doesn't post >1 "you fixed it" comments
9+
810
vows.describe('issue edit handler').addBatch(
911
handlerutil.setup('../../lib/issueedit', {
1012
'and we pass it the context of an issue edit with a null body': handlerutil.nullBody('don\'t see any text'),

utils/issue-format-bot/test/mocks/context.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ module.exports = {
2222
github: {
2323
issues: {
2424
createComment: sinon.spy(),
25+
// TODO actually make this keep track of data
26+
getComments: function() {
27+
return {
28+
data: []
29+
};
30+
},
2531
addLabels: sinon.spy(),
2632
removeLabel: sinon.spy(() => new Promise(noop))
2733
}

0 commit comments

Comments
 (0)