0

projector: add presubmit hook for metrics changes.

Add a presubmit hook to ensure that changes to metrics also
include a statement affirming that the author has updated the
metrics tracker.

Bug=b:271883148
Change-Id: Id3e4a8e17fa2ace5e4379c47988a7cae96a0eddb

Change-Id: Id3e4a8e17fa2ace5e4379c47988a7cae96a0eddb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4319528
Reviewed-by: Li Lin <llin@chromium.org>
Commit-Queue: Galen Corey <galenemco@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1116394}
This commit is contained in:
Galen Corey
2023-03-13 15:43:34 +00:00
committed by Chromium LUCI CQ
parent 88e296accf
commit 578b2ec8b9

@ -0,0 +1,30 @@
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Optional but recommended
PRESUBMIT_VERSION = '2.0.0'
# Mandatory: run under Python 3
USE_PYTHON3 = True
def CheckMetricsChangeHasTrackerUpdatedMessage(input_api, output_api):
"""Reminder to update metrics tracker and verify in CL description."""
description = input_api.change.DescriptionText()
metrics_tracker_re = input_api.re.compile(
r'PROJECTOR_METRICS_TRACKER_UPDATED|NO_METRICS_CHANGED')
metrics_file_re = input_api.re.compile(
r'.*chromium\/src\/ash\/projector\/projector_metrics\.cc')
error_message = ("If this CL adds, changes, or deletes a metric, please\n"
"update go/projector-metrics-tracker before submitting, then add\n"
"PROJECTOR_METRICS_TRACKER_UPDATED to the CL description. If there are\n"
"no changes to metrics in this CL, add NO_METRICS_CHANGED to the CL\n"
"description.")
for f in input_api.change.AffectedFiles(include_deletes=True,
file_filter=None):
if metrics_file_re.match(f.AbsoluteLocalPath(
)) and not metrics_tracker_re.match(description):
return [output_api.PresubmitError(error_message)]
return []