Add a --json option to git cl try-results.
For use in scripts that check try job results, this is
currently practically the same as making requests to
https://codereview.chromium.org/api/<cl-number>/<patchset-number>.
However, I think that this might be more future-proof, since
it fetches try job information from Buildbucket, and I expect
to still work after migration from Rietveld to Gerrit.
BUG=640354
Review-Url: https://codereview.chromium.org/2274743003
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 9796b2b..961801e 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -1484,7 +1484,7 @@
})
self.calls.append(
((['ask_for_data', 'If you know what you are doing, '
- 'press Enter to continue, Ctrl+C to abort.'],), ''))
+ 'press Enter to continue, Ctrl+C to abort.'],), ''))
self.assertIsNone(cl.EnsureAuthenticated(force=False))
def test_gerrit_ensure_authenticated_ok(self):
@@ -1850,6 +1850,54 @@
out.getvalue(),
'scheduled CQ Dry Run on https://codereview.chromium.org/123\n')
+ def test_write_try_results_json(self):
+ builds = {
+ '9000': {
+ 'id': '9000',
+ 'status': 'STARTED',
+ 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/2',
+ 'result_details_json': '{"properties": {}}',
+ 'bucket': 'master.x.y',
+ 'created_by': 'user:someone@chromium.org',
+ 'created_ts': '147200002222000',
+ 'parameters_json': '{"builder_name": "my-builder", "category": ""}',
+ },
+ '8000': {
+ 'id': '8000',
+ 'status': 'COMPLETED',
+ 'result': 'FAILURE',
+ 'failure_reason': 'BUILD_FAILURE',
+ 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/1',
+ 'result_details_json': '{"properties": {}}',
+ 'bucket': 'master.x.y',
+ 'created_by': 'user:someone@chromium.org',
+ 'created_ts': '147200001111000',
+ 'parameters_json': '{"builder_name": "my-builder", "category": ""}',
+ },
+ }
+ expected_output = [
+ {
+ 'buildbucket_id': '8000',
+ 'bucket': 'master.x.y',
+ 'builder_name': 'my-builder',
+ 'status': 'COMPLETED',
+ 'result': 'FAILURE',
+ 'failure_reason': 'BUILD_FAILURE',
+ 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/1',
+ },
+ {
+ 'buildbucket_id': '9000',
+ 'bucket': 'master.x.y',
+ 'builder_name': 'my-builder',
+ 'status': 'STARTED',
+ 'result': None,
+ 'failure_reason': None,
+ 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/2',
+ }
+ ]
+ self.calls = [(('write_json', 'output.json', expected_output), '')]
+ git_cl.write_try_results_json('output.json', builds)
+
def _common_GerritCommitMsgHookCheck(self):
self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
self.mock(git_cl.os.path, 'abspath',