ReviewBot: comment_write(): provide bot_name_suffix parameter.

Cleanly allows for multiple comments from the same tool on one entity.
This commit is contained in:
Jimmy Berry 2018-01-17 21:22:26 -06:00
parent f52b728333
commit 6631598dc6
2 changed files with 32 additions and 4 deletions

View File

@ -425,7 +425,7 @@ class ReviewBot(object):
def comment_write(self, state='done', result=None, project=None, package=None, def comment_write(self, state='done', result=None, project=None, package=None,
request=None, message=None, identical=False, only_replace=False, request=None, message=None, identical=False, only_replace=False,
info_extra=None, info_extra_identical=True): info_extra=None, info_extra_identical=True, bot_name_suffix=None):
"""Write comment if not similar to previous comment and replace old one. """Write comment if not similar to previous comment and replace old one.
The state, result, and info_extra (dict) are combined to create the info The state, result, and info_extra (dict) are combined to create the info
@ -472,18 +472,22 @@ class ReviewBot(object):
return return
message = '\n\n'.join(self.comment_handler.lines) message = '\n\n'.join(self.comment_handler.lines)
bot_name = self.bot_name
if bot_name_suffix:
bot_name = '::'.join([bot_name, bot_name_suffix])
info = {'state': state, 'result': result} info = {'state': state, 'result': result}
if info_extra and info_extra_identical: if info_extra and info_extra_identical:
info.update(info_extra) info.update(info_extra)
comments = self.comment_api.get_comments(**kwargs) comments = self.comment_api.get_comments(**kwargs)
comment, _ = self.comment_api.comment_find(comments, self.bot_name, info) comment, _ = self.comment_api.comment_find(comments, bot_name, info)
if info_extra and not info_extra_identical: if info_extra and not info_extra_identical:
# Add info_extra once comment has already been matched. # Add info_extra once comment has already been matched.
info.update(info_extra) info.update(info_extra)
message = self.comment_api.add_marker(message, self.bot_name, info) message = self.comment_api.add_marker(message, bot_name, info)
message = self.comment_api.truncate(message.strip()) message = self.comment_api.truncate(message.strip())
if (comment is not None and if (comment is not None and
@ -499,7 +503,7 @@ class ReviewBot(object):
if comment is None: if comment is None:
self.logger.debug('broadening search to include any state on {}'.format(debug_key)) self.logger.debug('broadening search to include any state on {}'.format(debug_key))
comment, _ = self.comment_api.comment_find(comments, self.bot_name) comment, _ = self.comment_api.comment_find(comments, bot_name)
if comment is not None: if comment is not None:
self.logger.debug('removing previous comment on {}'.format(debug_key)) self.logger.debug('removing previous comment on {}'.format(debug_key))
if not self.dryrun: if not self.dryrun:

View File

@ -132,6 +132,30 @@ class TestReviewBotComment(OBSLocalTestCase):
_, info = self.comments_filtered(self.bot) _, info = self.comments_filtered(self.bot)
self.assertEqual(info['state'], 'changed') self.assertEqual(info['state'], 'changed')
def test_bot_name_suffix(self):
suffix1 = 'suffix1'
bot_suffixed1 = '::'.join([self.bot, suffix1])
suffix2 = 'suffix2'
bot_suffixed2 = '::'.join([self.bot, suffix2])
self.review_bot.comment_write(bot_name_suffix=suffix1, project=PROJECT, message=COMMENT)
self.assertFalse(self.comments_filtered(self.bot)[0])
self.assertTrue(self.comments_filtered(bot_suffixed1)[0])
self.assertFalse(self.comments_filtered(bot_suffixed2)[0])
self.review_bot.comment_write(bot_name_suffix=suffix2, project=PROJECT, message=COMMENT)
self.assertFalse(self.comments_filtered(self.bot)[0])
self.assertTrue(self.comments_filtered(bot_suffixed1)[0])
self.assertTrue(self.comments_filtered(bot_suffixed2)[0])
self.review_bot.comment_write(bot_name_suffix=suffix1, project=PROJECT, message=COMMENT + '\nnew')
comment, _ = self.comments_filtered(bot_suffixed1)
self.assertTrue(comment['comment'].endswith(COMMENT + '\nnew'))
comment, _ = self.comments_filtered(bot_suffixed2)
self.assertTrue(comment['comment'].endswith(COMMENT))
def comments_filtered(self, bot): def comments_filtered(self, bot):
comments = self.api.get_comments(project_name=PROJECT) comments = self.api.get_comments(project_name=PROJECT)
return self.api.comment_find(comments, bot) return self.api.comment_find(comments, bot)