summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2024-09-16 17:20:05 +0100
committerDaniil Baturin <daniil@baturin.org>2024-09-16 17:20:05 +0100
commitbb4203d7c2f93a612cbad2e67c0f7d4c20d19f14 (patch)
tree21263947d1e90be89324278d877822d7f52bb3a0
parent5cd9d55166b35aae421616122bfb1fce2679559c (diff)
downloadvyos-infrastructure-main.tar.gz
vyos-infrastructure-main.zip
Add logic for tagging tasks based on their issue type and difficulty levelHEADmain
for ease of searching until Phorge adds native support for searching by custom fields
-rw-r--r--phabricator_tasks/get_task_data.py16
-rw-r--r--phabricator_tasks/tasks.py36
2 files changed, 51 insertions, 1 deletions
diff --git a/phabricator_tasks/get_task_data.py b/phabricator_tasks/get_task_data.py
index 6a2fef7..43d5301 100644
--- a/phabricator_tasks/get_task_data.py
+++ b/phabricator_tasks/get_task_data.py
@@ -1,6 +1,8 @@
'''
get all tasks and project information from vyos.dev
+Example:
+
{
"task_id": 6473,
"task_name": "bgp: missing completion helper for peer-groups inside a VRF",
@@ -15,6 +17,8 @@ get all tasks and project information from vyos.dev
"project_id": "PHID-PROJ-qakk4yrxprecshrgbehq"
}
],
+ "issue_type": "bug",
+ "difficulty_level": "easy",
"task_open": true
}
@@ -115,6 +119,16 @@ def unassign_task(task_id, token):
except Exception as e:
print(f'T{task_id} Error: {e}')
+def add_project(task_id, project, token):
+ phab = phab_api(token)
+ try:
+ response = phab.maniphest.edit(
+ objectIdentifier=task_id,
+ transactions=[{'type': 'projects.add', 'value': [project]}]
+ )
+ except Exception as e:
+ print(f'T{task_id} Error: {e}')
+
def get_task_data(token):
phab = phab_api(token)
# get list with all open status namens
@@ -155,6 +169,8 @@ def get_task_data(token):
'task_status': task['fields']['status']['value'],
'assigned_user': task['fields']['ownerPHID'],
'last_modified': task['fields']['dateModified'],
+ 'issue_type': task["fields"]["custom.issue-type"],
+ 'difficulty_level': task["fields"]["custom.difficulty-level"],
'projects': []
}
if task['fields']['status']['value'] in open_status_list:
diff --git a/phabricator_tasks/tasks.py b/phabricator_tasks/tasks.py
index 5504369..b0524dc 100644
--- a/phabricator_tasks/tasks.py
+++ b/phabricator_tasks/tasks.py
@@ -4,14 +4,23 @@ Phorge task chores:
1. Close a tasks if it's "Finished" in all boards but not yet resolved
2. Unassign tasks that are nominally assigned to someone but had no activity in a long time
+3. Tag tasks "Bug" if the type is "bug" for ease of searching
+ (since Phorge still can't search by custom fields...)
'''
import argparse
import json
-from get_task_data import get_task_data, close_task, unassign_task
+from get_task_data import get_task_data, close_task, unassign_task, add_project
from datetime import datetime, timedelta
+# Maniphest task editing endpoints that add tags
+# require internal PHIDs rather than human-readable named,
+# so we need to store those IDs somewhere.
+BUGS_PROJECT = 'PHID-PROJ-3fdkfs6vqiynjmthe2ay'
+UNCATEGORIZED_TASKS_PROJECT = 'PHID-PROJ-ivh4zv5rmncpcb6flbsb'
+BEGINNER_TASKS_RPOJECT = 'PHID-PROJ-ubzhyxbz2q5fprrkys7o'
+
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--token", type=str, help="API token", required=True)
parser.add_argument("-d", "--dry", help="dry run", action="store_true", default=False)
@@ -56,3 +65,28 @@ for task in tasks:
else:
unassign_task(task['task_id'], TOKEN)
+
+ # Tag tasks "Bug" for ease of searching
+ if task['issue_type'] in ['bug', 'vulnerability']:
+ print(f"Categorizing task T{task["task_id"]} as bug based on its issue type")
+ if DRYRUN:
+ pass
+ else:
+ add_project(task['task_id'], BUGS_PROJECT, TOKEN)
+
+ # Tag tasks "Uncategorized tasks" to draw maintainer attention to them
+ # if "Issue type" is not specified
+ if task['issue_type'] == 'unspecified':
+ print(f"Marking task T{task["task_id"]} uncategorized based on its issue type")
+ if DRYRUN:
+ pass
+ else:
+ add_project(task['task_id'], UNCATEGORIZED_TASKS_PROJECT, TOKEN)
+
+ # Tag tasks "Bug" for ease of searching
+ if task['difficulty_level'] == 'easy':
+ print(f"Categorizing task T{task["task_id"]} as a beginner task based on its difficulty level")
+ if DRYRUN:
+ pass
+ else:
+ add_project(task['task_id'], BUGS_PROJECT, TOKEN)