blob: 6630619918db8f52937706fe8160f22b909f7731 [file] [log] [blame]
qyearsley61be68b2015-07-06 12:57:02 -07001# Copyright 2015 The Chromium Authors. All rights reserved.
sullivan3283c9a2015-05-28 12:41:09 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for catapult.
6
7See https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
sullivan497af692015-08-11 10:39:21 -070010import re
Petr Cermak3946db22015-05-22 15:35:39 +010011import sys
sullivan3283c9a2015-05-28 12:41:09 -070012
sullivan7bb77ca2015-08-07 10:44:03 -070013_EXCLUDED_PATHS = (
dtua9d94bc2015-09-15 13:54:19 -070014 r'(.*[\\/])?\.git[\\/].*',
sullivan7bb77ca2015-08-07 10:44:03 -070015 r'.+\.png$',
16 r'.+\.svg$',
17 r'.+\.skp$',
18 r'.+\.gypi$',
19 r'.+\.gyp$',
20 r'.+\.gn$',
21 r'.*\.gitignore$',
22 r'.*codereview.settings$',
23 r'.*AUTHOR$',
24 r'^CONTRIBUTORS\.md$',
25 r'.*LICENSE$',
26 r'.*OWNERS$',
27 r'.*README\.md$',
sullivanf8f372d2017-05-12 14:16:25 -070028 r'^dashboard[\\/]dashboard[\\/]api[\\/]examples[\\/].*.js',
dtua9d94bc2015-09-15 13:54:19 -070029 r'^dashboard[\\/]dashboard[\\/]templates[\\/].*',
30 r'^experimental[\\/]heatmap[\\/].*',
primiano494b9b22017-04-10 13:15:36 -070031 r'^experimental[\\/]trace_on_tap[\\/]third_party[\\/].*',
dtua9d94bc2015-09-15 13:54:19 -070032 r'^perf_insights[\\/]test_data[\\/].*',
33 r'^perf_insights[\\/]third_party[\\/].*',
34 r'^third_party[\\/].*',
35 r'^tracing[\\/]\.allow-devtools-save$',
36 r'^tracing[\\/]bower\.json$',
37 r'^tracing[\\/]\.bowerrc$',
38 r'^tracing[\\/]tracing_examples[\\/]string_convert\.js$',
39 r'^tracing[\\/]test_data[\\/].*',
40 r'^tracing[\\/]third_party[\\/].*',
qyearsley4e6e99b2016-02-08 14:13:44 -080041 r'^telemetry[\\/]support[\\/]html_output[\\/]results-template.html',
sullivan7bb77ca2015-08-07 10:44:03 -070042)
43
sullivan3283c9a2015-05-28 12:41:09 -070044
petrcermakdad7f312016-06-01 05:49:22 -070045_CATAPULT_BUG_ID_RE = re.compile(r'#[1-9]\d*')
46_RIETVELD_BUG_ID_RE = re.compile(r'[1-9]\d*')
cwallezb287a2a2017-03-14 08:13:00 -070047_RIETVELD_REPOSITORY_NAMES = frozenset({'chromium', 'v8', 'angleproject'})
petrcermakdad7f312016-06-01 05:49:22 -070048
sullivan497af692015-08-11 10:39:21 -070049def CheckChangeLogBug(input_api, output_api):
petrcermakdad7f312016-06-01 05:49:22 -070050 # Show a presubmit message if there is no BUG= line.
51 if input_api.change.BUG is None:
52 return [output_api.PresubmitNotifyResult(
53 'If this change has associated Catapult and/or Rietveld bug(s), add a '
54 '"BUG=<bug>(, <bug>)*" line to the patch description where <bug> can '
55 'be one of the following: catapult:#NNNN, ' +
56 ', '.join('%s:NNNNNN' % n for n in _RIETVELD_REPOSITORY_NAMES) + '.')]
57
58 # Throw a presubmit error if the BUG= line is provided but empty.
59 if input_api.change.BUG.strip() == '':
60 return [output_api.PresubmitError(
61 'Empty BUG= line. Either remove it, or, preferably, change it to '
62 '"BUG=<bug>(, <bug>)*" where <bug> can be one of the following: ' +
63 'catapult:#NNNN, ' +
64 ', '.join('%s:NNNNNN' % n for n in _RIETVELD_REPOSITORY_NAMES) + '.')]
65
66 # Check that each bug in the BUG= line has the correct format.
67 error_messages = []
68 catapult_bug_provided = False
69 append_repository_order_error = False
70
71 for index, bug in enumerate(input_api.change.BUG.split(',')):
72 if index > 0:
73 bug = bug.lstrip() # Allow spaces after commas.
74
75 # Check if the bug can be split into a repository name and a bug ID (e.g.
76 # 'catapult:#1234' -> 'catapult' and '#1234').
77 bug_parts = bug.split(':')
78 if len(bug_parts) != 2:
79 error_messages.append('Invalid bug "%s". Bugs should be provided in the '
80 '"<repository-name>:<bug-id>" format.' % bug)
81 continue
82 repository_name, bug_id = bug_parts
83
84 if repository_name == 'catapult':
85 if not _CATAPULT_BUG_ID_RE.match(bug_id):
86 error_messages.append('Invalid bug "%s". Bugs in the Catapult '
87 'repository should be provided in the '
88 '"catapult:#NNNN" format.' % bug)
89 catapult_bug_provided = True
90 elif repository_name in _RIETVELD_REPOSITORY_NAMES:
91 if not _RIETVELD_BUG_ID_RE.match(bug_id):
92 error_messages.append('Invalid bug "%s". Bugs in the Rietveld %s '
93 'repository should be provided in the '
94 '"%s:NNNNNN" format.' % (bug, repository_name,
95 repository_name))
96 if catapult_bug_provided:
97 append_repository_order_error = True
98 else:
99 error_messages.append('Invalid bug "%s". Unknown repository "%s".' % (
100 bug, repository_name))
101
102 if append_repository_order_error:
103 error_messages.append('Please list Rietveld bugs (' +
104 ', '.join('%s:NNNNNN' % n
105 for n in _RIETVELD_REPOSITORY_NAMES) +
106 ') before Catapult bugs (catapult:#NNNN) so '
107 'that Rietveld would display them as hyperlinks.')
108
109 return map(output_api.PresubmitError, error_messages)
sullivan497af692015-08-11 10:39:21 -0700110
111
Petr Cermak3946db22015-05-22 15:35:39 +0100112def CheckChange(input_api, output_api):
sullivan1e388742015-08-03 13:45:35 -0700113 results = []
Petr Cermak3946db22015-05-22 15:35:39 +0100114 try:
115 sys.path += [input_api.PresubmitLocalPath()]
sullivan04bf4b52015-08-21 13:08:38 -0700116 from catapult_build import js_checks
qyearsleybd4fba62015-11-11 12:02:41 -0800117 from catapult_build import html_checks
petrcermak1fda6fc2016-02-24 10:15:03 -0800118 from catapult_build import repo_checks
sullivan497af692015-08-11 10:39:21 -0700119 results += input_api.canned_checks.PanProjectChecks(
120 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
sullivan497af692015-08-11 10:39:21 -0700121 results += CheckChangeLogBug(input_api, output_api)
qyearsleye080ff92015-08-17 11:19:59 -0700122 results += js_checks.RunChecks(
123 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
qyearsleybd4fba62015-11-11 12:02:41 -0800124 results += html_checks.RunChecks(
125 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
petrcermak1fda6fc2016-02-24 10:15:03 -0800126 results += repo_checks.RunChecks(input_api, output_api)
Petr Cermak3946db22015-05-22 15:35:39 +0100127 finally:
nducaa6e18a92015-08-09 17:06:32 -0700128 sys.path.remove(input_api.PresubmitLocalPath())
sullivan1e388742015-08-03 13:45:35 -0700129 return results
sullivanc11564b2015-06-25 10:37:29 -0700130
131
132def CheckChangeOnUpload(input_api, output_api):
Petr Cermak3946db22015-05-22 15:35:39 +0100133 return CheckChange(input_api, output_api)
sullivanc11564b2015-06-25 10:37:29 -0700134
135
136def CheckChangeOnCommit(input_api, output_api):
Petr Cermak3946db22015-05-22 15:35:39 +0100137 return CheckChange(input_api, output_api)