James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2013 OpenStack Foundation |
James E. Blair | 574ec76 | 2015-02-27 13:50:31 -0800 | [diff] [blame] | 3 | # Copyright 2015 Hewlett-Packard Development Company, L.P. |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 17 | import urllib2 |
| 18 | import json |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 19 | import argparse |
| 20 | |
| 21 | parser = argparse.ArgumentParser() |
| 22 | parser.add_argument('url', help='The URL of the running Zuul instance') |
| 23 | parser.add_argument('pipeline_name', help='The name of the Zuul pipeline') |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 24 | options = parser.parse_args() |
| 25 | |
| 26 | data = urllib2.urlopen('%s/status.json' % options.url).read() |
| 27 | data = json.loads(data) |
| 28 | |
| 29 | for pipeline in data['pipelines']: |
| 30 | if pipeline['name'] != options.pipeline_name: |
| 31 | continue |
| 32 | for queue in pipeline['change_queues']: |
| 33 | for head in queue['heads']: |
| 34 | for change in head: |
James E. Blair | 574ec76 | 2015-02-27 13:50:31 -0800 | [diff] [blame] | 35 | if not change['live']: |
| 36 | continue |
| 37 | cid, cps = change['id'].split(',') |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 38 | print( |
James E. Blair | 574ec76 | 2015-02-27 13:50:31 -0800 | [diff] [blame] | 39 | "zuul enqueue --trigger gerrit --pipeline %s " |
| 40 | "--project %s --change %s,%s" % ( |
| 41 | options.pipeline_name, |
| 42 | change['project'], |
| 43 | cid, cps) |
| 44 | ) |