summaryrefslogtreecommitdiff
path: root/chromium/third_party/metrics_proto/PRESUBMIT.py
blob: cc8979349e9a8ca3ab22a3ab5b25847650dfaadc (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
# Copyright 2018 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.

"""Presubmit script for metrics_proto.

See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details on the presubmit API built into gcl.
"""

README = 'README.chromium'


def IsMetricsProtoPath(input_api, path):
  return input_api.os_path.dirname(path) == input_api.PresubmitLocalPath()


def IsReadmeFile(input_api, path):
  return (input_api.basename(path) == README and
          IsMetricsProtoPath(input_api, path))


def CheckChange(input_api, output_api):
  """Checks that all changes include a README update."""
  paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles()]
  if (any((IsMetricsProtoPath(input_api, p) for p in paths)) and
      not any((IsReadmeFile(input_api, p) for p in paths))):
    return [output_api.PresubmitError(
            'Modifies %s without updating %s. '
            'Changes to these files should originate upstream.' %
            (input_api.PresubmitLocalPath(), README))]
  return []


def CheckChangeOnUpload(input_api, output_api):
  return CheckChange(input_api, output_api)


def CheckChangeOnCommit(input_api, output_api):
  return CheckChange(input_api, output_api)