Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index a1f58c8561f8129afd9cab9cf3de775fd5864d87..2a0b27492226a66168a44f7ec81ade81860fbb8c 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -398,7 +398,7 @@ def trigger_try_jobs(auth_config, changelist, options, masters, category): |
| def fetch_try_jobs(auth_config, changelist, options): |
| """Fetches try jobs from buildbucket. |
| - Returns a map from build id to build info as json dictionary. |
| + Returns a map from build id to build info as a dictionary. |
| """ |
| rietveld_url = settings.GetDefaultServerUrl() |
| rietveld_host = urlparse.urlparse(rietveld_url).hostname |
| @@ -533,6 +533,29 @@ def print_try_jobs(options, builds): |
| print('Total: %d try jobs' % total) |
| +def write_try_results_json(output_file, builds): |
| + """Writes a subset of the data from fetch_try_jobs to a file as JSON. |
| + |
| + The input |builds| dict is assumed to be generated by Buildbucket. |
| + Buildbucket documentation: http://goo.gl/G0s101 |
| + """ |
| + |
| + def convert_build_dict(build): |
| + return { |
| + 'buildbucket_id': build.get('id'), |
| + 'status': build.get('status'), |
| + 'result': build.get('result'), |
| + 'builder_name': json.loads( |
| + build.get('parameters_json', '{}')).get('builder_name'), |
|
tandrii(chromium)
2016/08/30 22:22:45
what about bucket_name? (that's where you can get
qyearsley
2016/08/30 23:41:24
Added bucket and url.
By category, do you mean so
tandrii(chromium)
2016/08/30 23:47:35
no, i meant parameters_json.category. It's usually
|
| + 'failure_reason': build.get('failure_reason'), |
|
qyearsley
2016/08/30 22:13:22
Does it seem like a good idea to use build['key']
tandrii(chromium)
2016/08/30 22:22:45
What's build['key']? I don't see it in buildbucket
qyearsley
2016/08/30 23:41:25
Ah, that's not a real thing, what I meant was "doe
tandrii(chromium)
2016/08/30 23:47:35
ah, dict.get() is the right way.
|
| + } |
| + |
| + converted = [] |
| + for _, build in sorted(builds.items()): |
| + converted.append(convert_build_dict(build)) |
| + write_json(output_file, converted) |
| + |
| + |
| def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
| """Return the corresponding git ref if |base_url| together with |glob_spec| |
| matches the full |url|. |
| @@ -4755,6 +4778,8 @@ def CMDtry_results(parser, args): |
| group.add_option( |
| "--buildbucket-host", default='cr-buildbucket.appspot.com', |
| help="Host of buildbucket. The default host is %default.") |
| + group.add_option( |
| + '--json', help='Path of JSON output file to write try job results to.') |
| parser.add_option_group(group) |
| auth.add_auth_options(parser) |
| options, args = parser.parse_args(args) |
| @@ -4783,7 +4808,10 @@ def CMDtry_results(parser, args): |
| print('ERROR: Exception when trying to fetch try jobs: %s\n%s' % |
| (e, stacktrace)) |
| return 1 |
| - print_try_jobs(options, jobs) |
| + if options.json: |
| + write_try_results_json(options.json, jobs) |
| + else: |
| + print_try_jobs(options, jobs) |
| return 0 |