bisect-kit: output candidates information in json

diagnose_cros_autotest.py and bisectors can use 'view --json' subcommand
to dump candidates information in machine readable format.

BUG=b:117860228
TEST=unittest; run diagnose_cros_autotest.py end-to-end test manually

Change-Id: Iafcfc79f6331575b5cbca2fb0e98ac1d577a1b46
Reviewed-on: https://chromium-review.googlesource.com/1337352
Commit-Ready: Kuang-che Wu <kcwu@chromium.org>
Tested-by: Kuang-che Wu <kcwu@chromium.org>
Reviewed-by: Chung-yih Wang <cywang@chromium.org>
diff --git a/bisect_cros_repo.py b/bisect_cros_repo.py
index 54b315b..b132a7f 100755
--- a/bisect_cros_repo.py
+++ b/bisect_cros_repo.py
@@ -35,6 +35,12 @@
 logger = logging.getLogger(__name__)
 
 
+def generate_action_link(action):
+  if action['action_type'] == 'commit':
+    repo_url = action['repo_url']
+    action['link'] = repo_url + '/+/' + action['rev']
+
+
 class ChromeOSRepoDomain(core.BisectDomain):
   """BisectDomain for ChromeOS code changes."""
   revtype = staticmethod(cros_util.argtype_cros_version)
@@ -125,15 +131,26 @@
     env['CHROMEOS_MIRROR'] = self.config['chromeos_mirror']
     env['INTRA_REV'] = rev
 
-  def view(self, revlist, old, new):
-    print('old', old)
-    print('new', new)
+  def fill_candidate_summary(self, summary, interesting_indexes):
+    old, new = summary['current_range']
+    old_base, _, _ = codechange.parse_intra_rev(old)
+    _, new_next, _ = codechange.parse_intra_rev(new)
+    old_short = cros_util.version_to_short(old_base)
+    new_short = cros_util.version_to_short(new_next)
+    url_template = 'https://crosland.corp.google.com/log/%s..%s'
+    summary['links'] = {
+        'change_list': url_template % (old_short, new_short),
+    }
 
-    spec_manager = cros_util.ChromeOSSpecManager(self.config)
     cache = repo_util.RepoMirror(self.config['chromeos_mirror'])
+    spec_manager = cros_util.ChromeOSSpecManager(self.config)
     code_manager = codechange.CodeManager(self.config['chromeos_root'],
                                           spec_manager, cache)
-    code_manager.view_rev_diff(revlist, old, new)
+    for i in interesting_indexes:
+      rev_info = summary['rev_info'][i]
+      rev_info.update(code_manager.get_rev_detail(rev_info['rev']))
+      for action in rev_info.get('actions', []):
+        generate_action_link(action)
 
 
 if __name__ == '__main__':