Commit 64a001ef authored by Sergiy Belozorov's avatar Sergiy Belozorov Committed by Commit Bot

Add support for retry command to buildbucket.py

R=nodir@chromium.org

Bug: 911143
Change-Id: Ia506f51687a7e4636e16746483931298dfd22027
Reviewed-on: https://chromium-review.googlesource.com/c/1356520Reviewed-by: 's avatarNodir Turakulov <nodir@chromium.org>
Commit-Queue: Sergiy Belozorov <sergiyb@chromium.org>
parent d87b0966
...@@ -20,6 +20,7 @@ import json ...@@ -20,6 +20,7 @@ import json
import urlparse import urlparse
import os import os
import sys import sys
import time
from third_party import httplib2 from third_party import httplib2
...@@ -76,6 +77,13 @@ def main(argv): ...@@ -76,6 +77,13 @@ def main(argv):
'from another command.' 'from another command.'
), ),
) )
retry_parser = subparsers.add_parser('retry')
retry_parser.add_argument(
'--id',
help='The ID of the build to retry.',
required=True,
)
args = parser.parse_args() args = parser.parse_args()
body = None body = None
...@@ -117,6 +125,9 @@ def main(argv): ...@@ -117,6 +125,9 @@ def main(argv):
}) })
method = 'PUT' method = 'PUT'
url = BUILDBUCKET_API_URL url = BUILDBUCKET_API_URL
elif args.command == 'retry':
method = 'PUT'
url = '%s/%s/retry' % (BUILDBUCKET_API_URL, args.id)
authenticator = auth.get_authenticator_for_host( authenticator = auth.get_authenticator_for_host(
BUILDBUCKET_URL, BUILDBUCKET_URL,
...@@ -124,6 +135,12 @@ def main(argv): ...@@ -124,6 +135,12 @@ def main(argv):
) )
http = authenticator.authorize(httplib2.Http()) http = authenticator.authorize(httplib2.Http())
http.force_exception_to_status_code = True http.force_exception_to_status_code = True
if args.verbose:
print 'Request URL:', url
print 'Request method:', method
print 'Request body:', body
response, content = http.request( response, content = http.request(
url, url,
method, method,
...@@ -132,10 +149,14 @@ def main(argv): ...@@ -132,10 +149,14 @@ def main(argv):
) )
if args.verbose: if args.verbose:
print content print 'Response:', response
print 'Content:', content
build_url = json.loads(content).get('build', {}).get('url') try:
if build_url: build_url = json.loads(content)['build']['url']
except (ValueError, TypeError, KeyError):
pass
else:
print 'Build triggered on: %s' % build_url print 'Build triggered on: %s' % build_url
return response.status != 200 return response.status != 200
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment