buildbucket: add --response-json.

Bug: 912391
Change-Id: I8302918397977e03fe7c10179f854ce385ad92e4
Reviewed-on: https://chromium-review.googlesource.com/c/1368884
Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org>
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
Commit-Queue: John Budorick <jbudorick@chromium.org>
changes/84/1368884/3
John Budorick 6 years ago committed by Commit Bot
parent 03ee2d6190
commit ec40d02c8a

@ -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

Loading…
Cancel
Save