def update_issue_comments(self, issue: Issue, comments_data: List[Dict], dry_run: bool) -> None: issue_id = issue.number if dry_run: print(f"Would update issue {issue_id} comments") return num_comments = len(comments_data) existing_comments = list(issue.get_comments()) # Create or update comments for comment_num, comment_data in enumerate(comments_data): print( f"Set comment {comment_num + 1}/{num_comments} of github issue #{issue_id}..." ) comment_body = comment_data["body"] if comment_num < len(existing_comments): existing_comments[comment_num].edit(comment_body) else: issue.create_comment(comment_body) # Delete comments in excess comments_to_delete = existing_comments[num_comments:] for i, gcomment in enumerate(comments_to_delete): print( f"Delete extra GitHub comment {i + 1}/{len(comments_to_delete)} of issue #{issue_id}..." ) gcomment.delete()
def check_if_removed_from_bugblog(bbt: Match, b: Tag, issue: Issue) -> None: if bbt is not None: text = strings.remove_smartquotes(bbt.group(1).strip()) for row in b.find_all('tr'): data = row.find_all('td') rowtext = strings.remove_smartquotes(data[1].text.strip()) if rowtext == text: break if strip_squarebrackets(rowtext) == strip_squarebrackets(text): # Fix this print( "Issue #{id}'s bug blog text has differing autocard notation." .format(id=issue.number)) old_bbt = strings.get_body_field(issue.body, 'Bug Blog Text') body = re.sub(BBT_REGEX, 'Bug Blog Text: {0}'.format(rowtext), issue.body, flags=re.MULTILINE) new_bbt = strings.get_body_field(body, 'Bug Blog Text') issue.edit(body=body) print('Updated to `{0}`'.format(rowtext)) issue.create_comment( f'Changed bug blog text from `{old_bbt}` to `{new_bbt}`') break else: print('{id} is fixed!'.format(id=issue.number)) repo.create_comment( issue, 'This bug has been removed from the bug blog!') issue.edit(state='closed')
def close_issue( *, issue: Issue, keyword_meta: KeywordMeta, keyword: str, label_strs: Set[str] ) -> None: logging.info( f"Clossing issue: #{issue.number} with message: {keyword_meta.message}" ) issue.create_comment(keyword_meta.message) issue.edit(state="closed") if keyword_meta.remove_label_on_close: if keyword in label_strs: issue.remove_from_labels(keyword)
def close_github_issue(repo: Repository, issue: Issue) -> None: """Close a github issue Parameters ---------- repo : Repository The repository issue : Issue The issue """ try: issue.create_comment(f"Imagery seems to work again.") issue.edit(state=ISSUE_CLOSED) except Exception as e: print(f"Failed to close issue: {e}")
def _add_duplicate_comment(issue: Issue, *, image: str, repo: str, run: str, stacktrace: str) -> IssueComment: """Comment on an existing error report.""" body = ( f"Probably duplicate error:\n" f"{_report_body(image=image, repo=repo, run=run, stacktrace=stacktrace)}" ) return issue.create_comment(body)
def _add_comment( self, github_issue: Issue, log: Log, ) -> IssueComment: comment_body = self._message_formatter.format_log(log=log, ) try: return github_issue.create_comment(body=comment_body, ) except GithubException as e: raise GitHubTrackerClientError( f'Unable to add GitHub comment for issue {github_issue} in project {self.configuration.project}', ) from e
def close_issue(*, issue: Issue, keyword_meta: KeywordMeta) -> None: logging.info( f"Clossing issue: #{issue.number} with message: {keyword_meta.message}" ) issue.create_comment(keyword_meta.message) issue.edit(state="closed")
def process_issue(issue: Issue) -> None: age = (datetime.datetime.now() - issue.updated_at).days if age < 5: fix_user_errors(issue) apply_screenshot_labels(issue) labels = [c.name for c in issue.labels] see_also = strings.get_body_field(issue.body, 'See Also') cards = get_affects(issue) if age < 5: check_for_invalid_card_names(issue, cards) update_issue_body(issue, cards, see_also) pd_legal = ([True for c in cards if c in pd_legal_cards()] or [False])[0] if pd_legal and not 'Affects PD' in labels: issue.add_to_labels('Affects PD') elif not pd_legal and 'Affects PD' in labels: issue.remove_from_labels('Affects PD') msg = issue.title categories = [c for c in labels if c in CATEGORIES] if not categories: if 'From Bug Blog' in labels: cat = 'Unclassified' else: cat = 'Unconfirmed' if not issue.comments: print( 'Issue #{id} was reported {days} ago, and has had no followup.' .format(id=issue.number, days=age)) if age > 30: issue.create_comment('Closing due to lack of followup.') issue.edit(state='closed') return if not 'Unclassified' in labels: issue.add_to_labels('Unclassified') elif 'Unclassified' in labels: print('Removing Unclassified from Issue #{id}'.format(id=issue.number)) issue.remove_from_labels('Unclassified') cat = categories.pop() else: cat = categories.pop() for card in cards: bannable = cat in BADCATS and 'Multiplayer' not in labels bug = { 'card': card, 'description': msg, 'category': cat, 'last_updated': str(issue.updated_at), 'pd_legal': card in pd_legal_cards(), 'bug_blog': 'From Bug Blog' in labels, 'breaking': cat in BADCATS, 'bannable': bannable, 'url': issue.html_url, } if 'Multiplayer' in labels: bug['multiplayer_only'] = True if 'Collection' in labels: bug['cade_bug'] = True if 'Deck Building' in labels: bug['cade_bug'] = True age = datetime.datetime.now() - issue.updated_at if 'Help Wanted' in labels: bug['help_wanted'] = True elif age.days > 60: bug['help_wanted'] = True bug['last_verified'] = VERIFICATION_BY_ISSUE.get(issue.number, None) ALL_BUGS.append(bug)
def create_comment(issue: Issue, body: str) -> IssueComment: set_issue_bbt(issue.number, None) return issue.create_comment(strings.remove_smartquotes(body))
def _add_comment( self, github_issue: Issue, log: Log, ) -> IssueComment: comment_body = self._message_formatter.format_log( log=log, ) + self._get_attachments_list_description( attachments=log.attachments, ) external_body = '' body_attachment = None if len(comment_body) > _TEXT_MAX_SIZE: external_body = comment_body body_attachment = self._build_external_description_attachment( name=f'comment-{log.log_id}-description.md', ) log_copy = deepcopy(log) log_copy.message_html = ( '<p>This comment is too large to fit into a GitHub comment. ' + f'See attachment <a href="{body_attachment.url}">{body_attachment.original_name}</a> ' + 'for more details.</p>' ) comment_body = self._message_formatter.format_log( log=log_copy, ) + self._get_attachments_list_description( attachments=[ body_attachment, *log.attachments, ], ) try: github_comment = github_issue.create_comment( body='This comment is being synchronized. Please check back in a moment.', ) except GithubException as e: raise GitHubTrackerClientError( f'Unable to add GitHub comment for issue {github_issue} in project {self.configuration.project}', ) from e comment_body, external_body = self._replace_attachments_references( uploads=self._upload_attachments( issue=github_issue, attachments=log.attachments, ), referencing_texts=[ comment_body, external_body, ], ) if body_attachment: body_attachment.data_loader = lambda: bytes(external_body, 'utf-8') comment_body = self._replace_attachments_references( uploads=self._upload_attachments( issue=github_issue, attachments=[ body_attachment, ], ), referencing_texts=[ comment_body, ], )[0] github_comment.edit( body=comment_body, ) return github_comment