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') |
James E. Blair | d05469e | 2017-09-29 09:04:15 -0700 | [diff] [blame] | 23 | parser.add_argument('tenant', help='The Zuul tenant') |
| 24 | parser.add_argument('pipeline', help='The name of the Zuul pipeline') |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 25 | options = parser.parse_args() |
| 26 | |
Monty Taylor | 9010dc5 | 2018-02-17 13:29:28 -0600 | [diff] [blame] | 27 | data = urllib2.urlopen('%s/status' % options.url).read() |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 28 | data = json.loads(data) |
| 29 | |
| 30 | for pipeline in data['pipelines']: |
James E. Blair | d05469e | 2017-09-29 09:04:15 -0700 | [diff] [blame] | 31 | if pipeline['name'] != options.pipeline: |
James E. Blair | c3b8eff | 2013-03-06 19:38:55 -0800 | [diff] [blame] | 32 | continue |
| 33 | for queue in pipeline['change_queues']: |
| 34 | for head in queue['heads']: |
| 35 | for change in head: |
James E. Blair | 574ec76 | 2015-02-27 13:50:31 -0800 | [diff] [blame] | 36 | if not change['live']: |
| 37 | continue |
| 38 | cid, cps = change['id'].split(',') |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 39 | print( |
James E. Blair | d05469e | 2017-09-29 09:04:15 -0700 | [diff] [blame] | 40 | "zuul enqueue --tenant %s --trigger gerrit " |
| 41 | "--pipeline %s --project %s --change %s,%s" % ( |
| 42 | options.tenant, |
| 43 | options.pipeline, |
James E. Blair | 574ec76 | 2015-02-27 13:50:31 -0800 | [diff] [blame] | 44 | change['project'], |
| 45 | cid, cps) |
| 46 | ) |