diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 799b4985c5d..101eebb97fa 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') @@ -329,6 +335,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 @@ -492,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 @@ -529,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): @@ -569,6 +587,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. @@ -622,11 +646,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 # ------------------------------------------------------------------------- @@ -713,6 +736,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: