Commit ec40d02c authored by John Budorick's avatar John Budorick Committed by Commit Bot

buildbucket: add --response-json.

Bug: 912391
Change-Id: I8302918397977e03fe7c10179f854ce385ad92e4
Reviewed-on: https://chromium-review.googlesource.com/c/1368884Reviewed-by: 's avatarSergiy Belozorov <sergiyb@chromium.org>
Reviewed-by: 's avatarNodir Turakulov <nodir@chromium.org>
Commit-Queue: John Budorick <jbudorick@chromium.org>
parent 03ee2d61
......@@ -34,6 +34,16 @@ BUILDBUCKET_API_URL = urlparse.urljoin(
)
def add_common_arguments(parser):
parser.add_argument(
'--response-json',
help=(
'A path to which the response JSON will be written. '
'If no valid JSON is received, nothing will be written.'
)
)
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument(
......@@ -42,13 +52,17 @@ def main(argv):
action='store_true',
)
subparsers = parser.add_subparsers(dest='command')
get_parser = subparsers.add_parser('get')
add_common_arguments(get_parser)
get_parser.add_argument(
'--id',
help='The ID of the build to get the status of.',
required=True,
)
put_parser = subparsers.add_parser('put')
add_common_arguments(put_parser)
put_parser.add_argument(
'-b',
'--bucket',
......@@ -77,7 +91,9 @@ def main(argv):
'from another command.'
),
)
retry_parser = subparsers.add_parser('retry')
add_common_arguments(retry_parser)
retry_parser.add_argument(
'--id',
help='The ID of the build to retry.',
......@@ -153,11 +169,15 @@ def main(argv):
print 'Content:', content
try:
build_url = json.loads(content)['build']['url']
content_json = json.loads(content)
if args.response_json:
with open(args.response_json, 'w') as response_json_file:
response_json_file.write(content)
build_url = content_json['build']['url']
except (ValueError, TypeError, KeyError):
pass
else:
print 'Build triggered on: %s' % build_url
print 'Build: %s' % build_url
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