Skip to content

Commit

Permalink
Fix method on_label_removal (#10)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
soehms authored Sep 21, 2023
1 parent f507826 commit 15f6f2e
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions .github/sync_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 15f6f2e

Please sign in to comment.