def post_messages(self, messages, max_comments):
# TODO: support non-PR runs
if not self.github:
return
messages_to_post = 0
messages_posted = 0
paths = dict()
# randomize message order to more evenly distribute messages across different files
messages = list(messages)
random.shuffle(messages)
if self.out_of_date():
return messages_to_post
start = time.time()
for msg in messages:
if system.should_stop() or (time.time() - start > 10 and self.out_of_date()):
return messages_to_post
if not msg.comments:
continue
msg_position = self.position(msg)
if msg_position:
messages_to_post += 1
if not self.is_duplicate(msg, msg_position):
# skip this message if we already have too many comments on this file
# max comments / 5 is an arbitrary number i totally made up. should maybe be configurable.
if paths.setdefault(msg.path, 0) > max_comments // 5:
continue
try:
self.pull_request.create_review_comment(
self.format_message(msg),
self.last_sha,
msg.path,
msg_position
)
except github3.GitHubError:
pass
paths[msg.path] += 1
messages_posted += 1
if max_comments >= 0 and messages_posted > max_comments:
break
print('{} messages posted to Github.'.format(messages_to_post))
return messages_to_post
评论列表
文章目录