From 7334e6386317e3e009282333d4ef045a3d699d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taavi=20V=C3=A4=C3=A4n=C3=A4nen?= Date: Fri, 25 Dec 2020 12:21:08 +0200 Subject: [PATCH] Add project grouper --- README.md | 1 + cron | 1 + lib.py | 9 +++++++++ project_grouper.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 project_grouper.py diff --git a/README.md b/README.md index 81d0c39..fd39e5a 100755 --- a/README.md +++ b/README.md @@ -4,4 +4,5 @@ Source for https://phabricator.wikimedia.org/p/Maintenance_bot/ Report issues and bugs: https://phabricator.wikimedia.org/project/board/5124/ * `column_mover.py` is a script that can move columns of a task when some actions happens on it. E.g. Moving a task in workboard #user-ladsgroup from column "incoming" to column "done" when someone changes the task's status to "done" +* `project_grouper.py` adds tasks in configured projects to other configured projects * `patchforreview_remover.py` is an automatic script that removes the "patch_for_review" tag when all patches have been merged or abandoned diff --git a/cron b/cron index d432eef..175148e 100644 --- a/cron +++ b/cron @@ -1,4 +1,5 @@ 15 * * * * jsub -once -N column_mover python3 /data/project/phabbot/phabbot/column_mover.py /data/project/phabbot/phabbot/creds.json 3600 >/dev/null 2>&1 +45 * * * * jsub -once -N column_mover python3 /data/project/phabbot/phabbot/project_grouper.py /data/project/phabbot/phabbot/creds.json 3600 >/dev/null 2>&1 10 * * * * jsub -once -N patch_for_review python3 /data/project/phabbot/phabbot/patchforreview_remover.py /data/project/phabbot/phabbot/creds.json 3600 >/dev/null 2>&1 5 * * * * jlocal bash /data/project/phabbot/phabbot/updater.sh >/dev/null 2>&1 10 22,4,10,16 * * * jsub -once -N new_wikis_handler bash /data/project/phabbot/phabbot/new_wikis_handler.sh >/dev/null 2>&1 diff --git a/lib.py b/lib.py index 060ee85..d2b1cf7 100755 --- a/lib.py +++ b/lib.py @@ -71,6 +71,15 @@ class Client(object): }] }) + def addTaskProject(self, task_phid, project_phid): + self.post('maniphest.edit', { + 'objectIdentifier': task_phid, + 'transactions': [{ + 'type': 'projects.add', + 'value': [project_phid], + }] + }) + def createSubtask(self, desc, project_phids, parent_phid, title): self.post('maniphest.edit', { 'objectIdentifier': '', diff --git a/project_grouper.py b/project_grouper.py new file mode 100644 index 0000000..77478ac --- /dev/null +++ b/project_grouper.py @@ -0,0 +1,31 @@ +""" +Adds tasks in configured projects to other configured projects +""" + +from lib import Client + +rules = [ + { + # current H175 - see T136921 + 'add': 'Design', + 'in': ['WMF-Design', 'WMDE-Design'], + }, +] + +client = Client.newFromCreds() + +for rule in rules: + handled_tasks = [] + + wanted_project_phid = client.lookupPhid('#' + rule['add']) + for project_name in rule['in']: + project_phid = client.lookupPhid('#' + project_name) + for task_phid in client.getTasksWithProject(project_phid): + # if a task is in multiple 'in' projects, still only process it once + if task_phid in handled_tasks: + continue + handled_tasks.append(task_phid) + + task = client.taskDetails(task_phid) + if wanted_project_phid not in task['projectPHIDs']: + client.addTaskProject(task_phid, wanted_project_phid)