James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2013 OpenStack Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # 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 | # Print commands to leave gerrit comments for every change in one of |
| 17 | # Zuul's pipelines. |
| 18 | |
| 19 | import urllib2 |
| 20 | import json |
| 21 | import sys |
| 22 | import argparse |
| 23 | |
| 24 | parser = argparse.ArgumentParser() |
| 25 | parser.add_argument('url', help='The URL of the running Zuul instance') |
| 26 | parser.add_argument('pipeline_name', help='The name of the Zuul pipeline') |
| 27 | parser.add_argument('comment', help='The text of the Gerrit comment') |
| 28 | parser.add_argument('--review-host', default='review', |
| 29 | help='The Gerrit hostname') |
| 30 | options = parser.parse_args() |
| 31 | |
| 32 | data = urllib2.urlopen('%s/status.json' % options.url).read() |
| 33 | data = json.loads(data) |
| 34 | |
| 35 | for pipeline in data['pipelines']: |
| 36 | if pipeline['name'] != options.pipeline_name: |
| 37 | continue |
| 38 | for queue in pipeline['change_queues']: |
| 39 | for head in queue['heads']: |
| 40 | for change in head: |
| 41 | print 'ssh %s gerrit review %s --message \\"%s\\"' % ( |
| 42 | options.review_host, |
| 43 | change['id'], |
| 44 | options.comment) |