Skip to content

Commit 15f6f2e

Browse files
authored
Fix method on_label_removal (sagemath#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
1 parent f507826 commit 15f6f2e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

.github/sync_labels.py

+28-6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(self, url, actor):
108108
self._url = url
109109
self._actor = actor
110110
self._warning_prefix = 'Label Sync Warning:'
111+
self._hint_prefix = 'Label Sync Hint:'
111112
self._labels = None
112113
self._author = None
113114
self._draft = None
@@ -262,10 +263,15 @@ def clean_warnings(self):
262263
created_at = c['created_at']
263264
if login.startswith('github-actions'):
264265
debug('github-actions comment %s created at %s on issue %s found' % (comment_id, created_at, issue))
266+
prefix = None
265267
if body.startswith(self._warning_prefix):
268+
prefix = self._warning_prefix
269+
if body.startswith(self._hint_prefix):
270+
prefix = self._hint_prefix
271+
if prefix:
266272
created = datetime.strptime(created_at, datetime_format)
267273
lifetime = today - created
268-
debug('github-actions %s %s is %s old' % (self._warning_prefix, comment_id, lifetime))
274+
debug('github-actions %s %s is %s old' % (prefix, comment_id, lifetime))
269275
if lifetime > warning_lifetime:
270276
try:
271277
self.rest_api('%s/%s' % (path_args, comment_id), method='DELETE')
@@ -494,8 +500,15 @@ def actor_valid(self):
494500
return False
495501

496502
coms = self.get_commits()
497-
authors = sum(com['authors'] for com in coms)
498-
authors = [auth for auth in authors if not auth['login'] in (self._actor, 'github-actions')]
503+
authors = []
504+
for com in coms:
505+
for author in com['authors']:
506+
login = author['login']
507+
if not login in authors:
508+
if not login in (self._actor, 'github-actions'):
509+
debug('PR %s has recent commit by %s' % (self._issue, login))
510+
authors.append(login)
511+
499512
if not authors:
500513
info('PR %s can\'t be approved by the author %s since no other person commited to it' % (self._issue, self._actor))
501514
return False
@@ -571,6 +584,12 @@ def add_warning(self, text):
571584
"""
572585
self.add_comment('%s %s' % (self._warning_prefix, text))
573586

587+
def add_hint(self, text):
588+
r"""
589+
Perform a system call to ``gh`` to add a hint to an issue or PR.
590+
"""
591+
self.add_comment('%s %s' % (self._hint_prefix, text))
592+
574593
def add_label(self, label):
575594
r"""
576595
Add the given label to the issue or PR.
@@ -624,11 +643,10 @@ def reject_label_removal(self, item):
624643
a corresponding other one.
625644
"""
626645
if type(item) == State:
627-
sel_list = 'state'
646+
sel_list = 'status'
628647
else:
629648
sel_list = 'priority'
630-
self.add_warning('Label *%s* can not be removed. Please add the %s-label which should replace it' % (item.value, sel_list))
631-
self.add_label(item.value)
649+
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)
632650
return
633651

634652
# -------------------------------------------------------------------------
@@ -715,6 +733,10 @@ def on_label_removal(self, label):
715733
return
716734

717735
item = sel_list(label)
736+
737+
if len(self.active_partners(item)) > 0:
738+
return
739+
718740
if sel_list is State:
719741
if self.is_pull_request():
720742
if item != State.needs_info:

0 commit comments

Comments
 (0)