1
0
Fork 0
mirror of https://gitlab.wikimedia.org/ladsgroup/Phabricator-maintenance-bot synced 2024-11-21 11:32:38 +01:00

Added some comments

This commit is contained in:
Ahmon Dancy 2023-01-19 10:10:16 -08:00
parent 97a38359f6
commit 9b64c4b501
2 changed files with 25 additions and 4 deletions

2
lib.py
View file

@ -11,7 +11,7 @@ class Client(object):
def __init__(self, url, username, key):
self.url = url
self.username = username
self.username = username # Unused
self.column_cache = {}
self.phid_cache = {}
self.session = {

View file

@ -12,17 +12,29 @@ class Checker():
self.client = client
def check(self, t_id):
"""
Returns true if the Patch-For-Review project should be removed from the Phabricator
task identified 't_id'.
"""
phid = self.client.lookupPhid(t_id)
return self.phid_check(phid)
def phid_check(self, phid):
def phid_check(self, phid) -> bool:
"""
Returns true if the Patch-For-Review project should be removed from the Phabricator
task identified by 'phid'.
"""
gerrit_bot_actions = []
# Note that transactions are returned in reverse chronological order (most recent first).
for transaction in self.client.getTransactions(phid):
if re.findall(re.escape('https://github.com/') + r'.+?/pull', str(transaction)):
return False
if transaction['authorPHID'] == self.gerrit_bot_phid:
gerrit_bot_actions.append(transaction)
else:
# If someone other than GerritBot adds the Patch-For-Review project, don't
# auto-remove it.
if transaction['type'] == 'projects':
check = self.project_patch_for_review_phid in str(
transaction['fields'])
@ -44,9 +56,17 @@ class Checker():
r'Change \d+ \*\*(?:merged|abandoned)\*\* by ',
raw_comment)
# Append True or False depending on whether the action was to
# open a patch (True) or merge a patch (False)
gerrit_patch_status[gerrit_patch_id].append(not(bool(merged)))
for patch in gerrit_patch_status:
# The normal sequence of GerritBot transactions for a Gerrit change is "Change
# \d+ had a related patch set uploaded" (indicated by True in
# gerrit_patch_status) eventually followed by "Change \d+ (merged|abandoned)
# by whoever" (indicated by False in gerrit_patch_status). The transactions
# are returned in reverse order so the opened/merged pattern will appear as
# the reverse of [True, False], which is [False, True].
if gerrit_patch_status[patch] != [False, True]:
return False
return True
@ -54,9 +74,10 @@ class Checker():
client = Client.newFromCreds()
gerrit_bot_phid = 'PHID-USER-idceizaw6elwiwm5xshb'
project_patch_for_review_phid = 'PHID-PROJ-onnxucoedheq3jevknyr'
checker = Checker(
'PHID-USER-idceizaw6elwiwm5xshb',
gerrit_bot_phid,
project_patch_for_review_phid,
client)
gen = client.getTasksWithProject(project_patch_for_review_phid)