blob: 12e6916b954a02af7cb401b9de4f4595be9eee4a [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,
James E. Blair82fd8832017-02-27 13:24:02 -080070 'invalid': None,
James E. Blair86dfb642016-12-05 15:05:09 -080071}
72
73
74def main():
75 requests.packages.urllib3.disable_warnings()
76 # logging.basicConfig(level=logging.DEBUG)
77 app = App()
78 app.config = boartty.config.Config('openstack')
79 sync = boartty.sync.Sync(app, False)
80 board = sync.get('v1/boards/41')
81 tasks = get_tasks(sync)
82
83 lanes = dict()
84 for lane in board['lanes']:
85 lanes[lane['worklist']['title']] = lane
86
87 for task in tasks:
88 ok_lanes = MAP[task['status']]
89 task_found = False
90 for lane_name, lane in lanes.items():
91 if task_in_lane(task, lane):
92 if ok_lanes and lane_name in ok_lanes:
93 task_found = True
94 else:
95 remove_task(sync, task, lane)
96 if ok_lanes and not task_found:
97 add_task(sync, task, lanes[ok_lanes[0]])
98
99if __name__ == '__main__':
100 main()