summaryrefslogtreecommitdiffstats
path: root/tools/auto_bisect/bisect_results_json.py
blob: 210159cdc99ed9475b576041bb4583e915736149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os

import bisect_utils
import source_control


def Get(bisect_results, opts, depot_registry):
  """Returns the results as a jsonable object."""
  if opts.bisect_mode == bisect_utils.BISECT_MODE_RETURN_CODE:
    change = '0'
  else:
    metric = '/'.join(opts.metric)
    change = '%.02f%%' % bisect_results.regression_size

  status = 'completed'

  return {
      'try_job_id': opts.try_job_id,
      'bug_id': opts.bug_id,
      'status': status,
      'buildbot_log_url': _GetBuildBotLogUrl(),
      'bisect_bot': os.environ.get('BUILDBOT_BUILDERNAME', ''),
      'command': opts.command,
      'metric': metric,
      'change': change,
      'score': bisect_results.confidence,
      'good_revision': opts.good_revision,
      'bad_revision': opts.bad_revision,
      'warnings': bisect_results.warnings,
      'abort_reason': bisect_results.abort_reason,
      'culprit_data': _CulpritData(bisect_results),
      'revision_data': _RevisionData(bisect_results, depot_registry),
  }


def _CulpritData(bisect_results):
  if not bisect_results.culprit_revisions:
    return None
  cl, culprit_info, depot = bisect_results.culprit_revisions[0]
  commit_link = _GetViewVCLinkFromDepotAndHash(cl, depot)
  if commit_link:
    commit_link = '\nLink    : %s' % commit_link
  else:
    commit_link = ('\Description:\n%s' % culprit_info['body'])

  return {
      'subject': culprit_info['subject'],
      'author': culprit_info['email'],
      'email': culprit_info['email'],
      'cl_date': culprit_info['date'],
      'commit_info': commit_link,
      'revisions_links': [],
      'cl': cl
  }


def _RevisionData(bisect_results, depot_registry):
  revision_rows = []
  for state in bisect_results.state.GetRevisionStates():
    commit_position = source_control.GetCommitPosition(
        state.revision, depot_registry.GetDepotDir(state.depot))
    revision_rows.append({
        'depot_name': state.depot,
        'deps_revision': state.revision,
        'commit_pos': commit_position,
        'result': 'good' if state.passed else 'bad',
    })
  return revision_rows


def _GetViewVCLinkFromDepotAndHash(git_revision, depot):
  """Gets link to the repository browser."""
  if depot and 'viewvc' in bisect_utils.DEPOT_DEPS_NAME[depot]:
    return bisect_utils.DEPOT_DEPS_NAME[depot]['viewvc'] + git_revision
  return ''


def _GetBuildBotLogUrl():
  master_url = os.environ.get('BUILDBOT_BUILDBOTURL')
  builder_name = os.environ.get('BUILDBOT_BUILDERNAME')
  builder_number = os.environ.get('BUILDBOT_BUILDNUMBER')
  if master_url and builder_name and builder_number:
    return '%s%s/%s' % (master_url, builder_name, builder_number)
  return ''