| # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """Code for interacting with CIDB.""" |
| |
| from __future__ import print_function |
| from __future__ import absolute_import |
| from __future__ import division |
| |
| from chromite.lib import constants |
| from chromite.lib import clactions |
| from chromite.lib import cros_logging as logging |
| |
| from infra_libs import ts_mon |
| |
| |
| # TODO(phobbs) include "forgiven due to pre CQ flake" |
| _EXONERATOR_REASON = { |
| 'cq': 'annotations_finalized', |
| 'pre-cq': 'forgiven_due_to_sanity_build_failure' |
| } |
| |
| _EXONERATED_METRIC = ts_mon.CounterMetric( |
| 'chromeos/exonerator/exonerations_performed', |
| description='A count of exoneration events.', |
| field_spec=[ |
| ts_mon.StringField('reason'), |
| ts_mon.StringField('exoneration_type')] |
| ) |
| |
| |
| def InsertExoneratedCLActions(conn, changes, exoneration_type): |
| """Inserts a CLAction indicating a CL was exonerated. |
| |
| Args: |
| conn: A CIDBConnection |
| changes: A sequence of ChangeWithBuild tuples. |
| exoneration_type: a string in ('cq', 'pre-cq'), representing the type of |
| exoneration that was performed. |
| """ |
| logging.info("Inserting 'exonerated' CLActions for %s", map(str, changes)) |
| actions = [] |
| for change, _build_id in changes: |
| reason = _EXONERATOR_REASON[exoneration_type] |
| actions.append(clactions.CLAction.FromGerritPatchAndAction( |
| change, |
| action=constants.CL_ACTION_EXONERATED, |
| reason=reason, |
| )) |
| _EXONERATED_METRIC.increment(fields={ |
| 'reason': reason, |
| 'exoneration_type': exoneration_type, |
| }) |
| conn.InsertCLActions(build_id=None, cl_actions=actions) |