OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 """Top-level presubmit script for Skia. | 6 """Top-level presubmit script for Skia. |
7 | 7 |
8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
9 for more details about the presubmit API built into gcl. | 9 for more details about the presubmit API built into gcl. |
10 """ | 10 """ |
11 | 11 |
12 import os | 12 import os |
| 13 import re |
13 import sys | 14 import sys |
14 | 15 |
15 | 16 |
| 17 REVERT_CL_SUBJECT_PREFIX = 'Revert ' |
| 18 |
16 SKIA_TREE_STATUS_URL = 'http://skia-tree-status.appspot.com' | 19 SKIA_TREE_STATUS_URL = 'http://skia-tree-status.appspot.com' |
17 | 20 |
18 PUBLIC_API_OWNERS = ( | 21 PUBLIC_API_OWNERS = ( |
19 'reed@chromium.org', | 22 'reed@chromium.org', |
20 'reed@google.com', | 23 'reed@google.com', |
21 'bsalomon@chromium.org', | 24 'bsalomon@chromium.org', |
22 'bsalomon@google.com', | 25 'bsalomon@google.com', |
23 'rmistry@google.com', # For emergency reverts only. | |
24 ) | 26 ) |
25 | 27 |
26 | 28 |
27 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): | 29 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): |
28 """Checks that files end with atleast one \n (LF).""" | 30 """Checks that files end with atleast one \n (LF).""" |
29 eof_files = [] | 31 eof_files = [] |
30 for f in input_api.AffectedSourceFiles(source_file_filter): | 32 for f in input_api.AffectedSourceFiles(source_file_filter): |
31 contents = input_api.ReadFile(f, 'rb') | 33 contents = input_api.ReadFile(f, 'rb') |
32 # Check that the file ends in atleast one newline character. | 34 # Check that the file ends in atleast one newline character. |
33 if len(contents) > 1 and contents[-1:] != '\n': | 35 if len(contents) > 1 and contents[-1:] != '\n': |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 requires_owner_check = True | 122 requires_owner_check = True |
121 | 123 |
122 if not requires_owner_check: | 124 if not requires_owner_check: |
123 return results | 125 return results |
124 | 126 |
125 lgtm_from_owner = False | 127 lgtm_from_owner = False |
126 issue = input_api.change.issue | 128 issue = input_api.change.issue |
127 if issue and input_api.rietveld: | 129 if issue and input_api.rietveld: |
128 issue_properties = input_api.rietveld.get_issue_properties( | 130 issue_properties = input_api.rietveld.get_issue_properties( |
129 issue=int(issue), messages=True) | 131 issue=int(issue), messages=True) |
| 132 if re.match(REVERT_CL_SUBJECT_PREFIX, issue_properties['subject'], re.I): |
| 133 # It is a revert CL, ignore the public api owners check. |
| 134 return results |
130 if issue_properties['owner_email'] in PUBLIC_API_OWNERS: | 135 if issue_properties['owner_email'] in PUBLIC_API_OWNERS: |
131 # An owner created the CL that is an automatic LGTM. | 136 # An owner created the CL that is an automatic LGTM. |
132 lgtm_from_owner = True | 137 lgtm_from_owner = True |
133 | 138 |
134 messages = issue_properties.get('messages') | 139 messages = issue_properties.get('messages') |
135 if messages: | 140 if messages: |
136 for message in messages: | 141 for message in messages: |
137 if (message['sender'] in PUBLIC_API_OWNERS and | 142 if (message['sender'] in PUBLIC_API_OWNERS and |
138 'lgtm' in message['text'].lower()): | 143 'lgtm' in message['text'].lower()): |
139 # Found an lgtm in a message from an owner. | 144 # Found an lgtm in a message from an owner. |
140 lgtm_from_owner = True | 145 lgtm_from_owner = True |
141 break; | 146 break; |
142 | 147 |
143 if not lgtm_from_owner: | 148 if not lgtm_from_owner: |
144 results.append( | 149 results.append( |
145 output_api.PresubmitError( | 150 output_api.PresubmitError( |
146 'Since the CL is editing public API, you must have an LGTM from ' | 151 'Since the CL is editing public API, you must have an LGTM from ' |
147 'one of: %s' % str(PUBLIC_API_OWNERS))) | 152 'one of: %s' % str(PUBLIC_API_OWNERS))) |
148 return results | 153 return results |
149 | 154 |
150 | 155 |
151 def CheckChangeOnCommit(input_api, output_api): | 156 def CheckChangeOnCommit(input_api, output_api): |
152 """Presubmit checks for the change on commit. | 157 """Presubmit checks for the change on commit. |
153 | 158 |
154 The following are the presubmit checks: | 159 The following are the presubmit checks: |
155 * Check change has one and only one EOL. | 160 * Check change has one and only one EOL. |
156 * Ensures that the Skia tree is open in | 161 * Ensures that the Skia tree is open in |
157 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' | 162 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' |
158 state and an error if it is in 'Closed' state. | 163 state and an error if it is in 'Closed' state. |
159 """ | 164 """ |
160 results = [] | 165 results = [] |
161 results.extend(_CommonChecks(input_api, output_api)) | 166 results.extend(_CommonChecks(input_api, output_api)) |
162 results.extend( | 167 results.extend( |
163 _CheckTreeStatus(input_api, output_api, json_url=( | 168 _CheckTreeStatus(input_api, output_api, json_url=( |
164 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 169 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
165 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 170 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
166 return results | 171 return results |
OLD | NEW |