1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
'''
implement Tasks checks and workflows on vyos.dev
1. Close a tasks if the Task is in all "Finished" columns
'''
import argparse
import json
from phabricator_tasks.get_task_data import get_task_data, close_task, unassign_task
from datetime import datetime, timedelta
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)
args = parser.parse_args()
TOKEN = args.token
DRYRUN = args.dry
# DRYRUN = True
UMASIGN_AFTER_DAYS = 90
UMASIGN_AFTER_DAYS = timedelta(days=UMASIGN_AFTER_DAYS)
NOW = datetime.now()
if DRYRUN:
print("This is a dry run")
tasks = get_task_data(TOKEN)
for task in tasks:
# close tasks it is in any projects "finished" column
if len(task['projects']) > 0:
finished = True
for project in task['projects']:
if project['column_name'] != 'Finished':
finished = False
break
if finished:
if DRYRUN:
print(f'dryrun: T{task["task_id"]} would be closed')
else:
close_task(task['task_id'], TOKEN)
continue
'''
# unassign tasks with no process after UMASIGN_AFTER_DAYS
if task['assigned_user'] and task['assigned_time']:
delta = NOW - datetime.fromtimestamp(int(task['assigned_time']))
if delta > UMASIGN_AFTER_DAYS:
if task['task_status'] != 'open':
if DRYRUN:
print(f'dryrun: T{task["task_id"]} with status {task['task_status']} would be unassigned after {delta.days} days')
else:
unassign_task(task['task_id'], TOKEN)
continue
'''
|