From f50782649d4b26011f844208de791fa0c26a46ac Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 18 Sep 2023 08:06:03 +0200 Subject: [PATCH 1/3] sync_labels_fixes_part2 initial --- .github/sync_labels.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 799b4985c5d..42724f9fa12 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -329,6 +329,8 @@ def get_review_decision(self): else: # To separate a not supplied value from not cached (see https://github.com/sagemath/sage/pull/36177#issuecomment-1704022893 ff) self._review_decision = ReviewDecision.unclear + info('No review decision for %s' % self._issue) + return None info('Review decision for %s: %s' % (self._issue, self._review_decision.value)) return self._review_decision @@ -539,7 +541,7 @@ def approve(self): r""" Approve the PR by the actor. """ - self.review('--approve', '%s approved this PR' % self._actor) + self.review('--approve', '@%s approved this PR' % self._actor) info('PR %s approved by %s' % (self._issue, self._actor)) def request_changes(self): From 15f6f2e0df3f48f93ee6f112f3e26afcb88f9bc5 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms <47305845+soehms@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:54:18 +0200 Subject: [PATCH 2/3] Fix method on_label_removal (#10) * fix_on_label_removal initial * fix_on_label_removal state -> status * fix bug in actor valid * once again * rewrite authors in actor_valid * syntax * replace warning by hint --- .github/sync_labels.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 42724f9fa12..4bdb10e7d05 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -108,6 +108,7 @@ def __init__(self, url, actor): self._url = url self._actor = actor self._warning_prefix = 'Label Sync Warning:' + self._hint_prefix = 'Label Sync Hint:' self._labels = None self._author = None self._draft = None @@ -262,10 +263,15 @@ def clean_warnings(self): created_at = c['created_at'] if login.startswith('github-actions'): debug('github-actions comment %s created at %s on issue %s found' % (comment_id, created_at, issue)) + prefix = None if body.startswith(self._warning_prefix): + prefix = self._warning_prefix + if body.startswith(self._hint_prefix): + prefix = self._hint_prefix + if prefix: created = datetime.strptime(created_at, datetime_format) lifetime = today - created - debug('github-actions %s %s is %s old' % (self._warning_prefix, comment_id, lifetime)) + debug('github-actions %s %s is %s old' % (prefix, comment_id, lifetime)) if lifetime > warning_lifetime: try: self.rest_api('%s/%s' % (path_args, comment_id), method='DELETE') @@ -494,8 +500,15 @@ def actor_valid(self): return False coms = self.get_commits() - authors = sum(com['authors'] for com in coms) - authors = [auth for auth in authors if not auth['login'] in (self._actor, 'github-actions')] + authors = [] + for com in coms: + for author in com['authors']: + login = author['login'] + if not login in authors: + if not login in (self._actor, 'github-actions'): + debug('PR %s has recent commit by %s' % (self._issue, login)) + authors.append(login) + if not authors: info('PR %s can\'t be approved by the author %s since no other person commited to it' % (self._issue, self._actor)) return False @@ -571,6 +584,12 @@ def add_warning(self, text): """ self.add_comment('%s %s' % (self._warning_prefix, text)) + def add_hint(self, text): + r""" + Perform a system call to ``gh`` to add a hint to an issue or PR. + """ + self.add_comment('%s %s' % (self._hint_prefix, text)) + def add_label(self, label): r""" Add the given label to the issue or PR. @@ -624,11 +643,10 @@ def reject_label_removal(self, item): a corresponding other one. """ if type(item) == State: - sel_list = 'state' + sel_list = 'status' else: sel_list = 'priority' - self.add_warning('Label *%s* can not be removed. Please add the %s-label which should replace it' % (item.value, sel_list)) - self.add_label(item.value) + self.add_hint('You don\'t need to remove %s labels any more. You\'d better just add the label which replaces it' % sel_list) return # ------------------------------------------------------------------------- @@ -715,6 +733,10 @@ def on_label_removal(self, label): return item = sel_list(label) + + if len(self.active_partners(item)) > 0: + return + if sel_list is State: if self.is_pull_request(): if item != State.needs_info: From 3c5a08ac126e93f1bbdf1437e1fe241f5a9723aa Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 26 Sep 2023 18:52:35 +0200 Subject: [PATCH 3/3] approve_without_body initial --- .github/sync_labels.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 4bdb10e7d05..101eebb97fa 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -544,24 +544,27 @@ def mark_as_ready(self): """ self.gh_cmd('ready', '', '') - def review(self, arg, text): + def review(self, arg, text=None): r""" Perform a system call to ``gh`` to review a PR. """ - self.gh_cmd('review', arg, '-b \"%s\"' % text) + if text: + self.gh_cmd('review', arg, '-b \"%s\"' % text) + else: + self.gh_cmd('review', arg) def approve(self): r""" Approve the PR by the actor. """ - self.review('--approve', '@%s approved this PR' % self._actor) + self.review('--approve') info('PR %s approved by %s' % (self._issue, self._actor)) def request_changes(self): r""" Request changes for this PR by the actor. """ - self.review('--request-changes', '%s requested changes for this PR' % self._actor) + self.review('--request-changes', '@%s requested changes for this PR' % self._actor) info('Changes requested for PR %s by %s' % (self._issue, self._actor)) def review_comment(self, text):