blob: 6800a35df306eea41e79c04b9ead79e6005d7bf0 [file] [log] [blame]
James E. Blair86dfb642016-12-05 15:05:09 -08001#!/usr/bin/env python
2# Copyright (C) 2016 Red Hat, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16# This script updates the Zuul v3 Storyboard. It uses a .boartty.yaml
17# file to get credential information.
18
19import requests
20import boartty.config
21import boartty.sync
22import logging # noqa
23from pprint import pprint as p # noqa
24
25
26class App(object):
27 pass
28
29
30def get_tasks(sync):
31 task_list = []
32 for story in sync.get('/v1/stories?tags=zuulv3'):
33 print("Story %s: %s" % (story['id'], story['title']))
34 for task in sync.get('/v1/stories/%s/tasks' % (story['id'])):
35 print(" %s" % (task['title'],))
36 task_list.append(task)
37 return task_list
38
39
40def task_in_lane(task, lane):
41 for item in lane['worklist']['items']:
42 if 'task' in item and item['task']['id'] == task['id']:
43 return True
44 return False
45
46
47def add_task(sync, task, lane):
48 print("Add task %s to %s" % (task['id'], lane['worklist']['id']))
49 r = sync.post('v1/worklists/%s/items/' % lane['worklist']['id'],
50 dict(item_id=task['id'],
51 item_type='task',
52 list_position=0))
53 print(r)
54
55
56def remove_task(sync, task, lane):
57 print("Remove task %s from %s" % (task['id'], lane['worklist']['id']))
58 for item in lane['worklist']['items']:
59 if 'task' in item and item['task']['id'] == task['id']:
60 r = sync.delete('v1/worklists/%s/items/' % lane['worklist']['id'],
61 dict(item_id=item['id']))
62 print(r)
63
64
65MAP = {
66 'todo': ['New', 'Backlog', 'Todo'],
67 'inprogress': ['In Progress', 'Blocked'],
68 'review': ['In Progress', 'Blocked'],
69 'merged': None,
70}
71
72
73def main():
74 requests.packages.urllib3.disable_warnings()
75 # logging.basicConfig(level=logging.DEBUG)
76 app = App()
77 app.config = boartty.config.Config('openstack')
78 sync = boartty.sync.Sync(app, False)
79 board = sync.get('v1/boards/41')
80 tasks = get_tasks(sync)
81
82 lanes = dict()
83 for lane in board['lanes']:
84 lanes[lane['worklist']['title']] = lane
85
86 for task in tasks:
87 ok_lanes = MAP[task['status']]
88 task_found = False
89 for lane_name, lane in lanes.items():
90 if task_in_lane(task, lane):
91 if ok_lanes and lane_name in ok_lanes:
92 task_found = True
93 else:
94 remove_task(sync, task, lane)
95 if ok_lanes and not task_found:
96 add_task(sync, task, lanes[ok_lanes[0]])
97
98if __name__ == '__main__':
99 main()