Chromium Code Reviews| 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 fnmatch | 12 import fnmatch |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import subprocess | |
| 15 import sys | 16 import sys |
| 16 import traceback | 17 import traceback |
| 17 | 18 |
| 18 | 19 |
| 19 REVERT_CL_SUBJECT_PREFIX = 'Revert ' | 20 REVERT_CL_SUBJECT_PREFIX = 'Revert ' |
| 20 | 21 |
| 21 SKIA_TREE_STATUS_URL = 'http://skia-tree-status.appspot.com' | 22 SKIA_TREE_STATUS_URL = 'http://skia-tree-status.appspot.com' |
| 22 | 23 |
| 23 # Please add the complete email address here (and not just 'xyz@' or 'xyz'). | 24 # Please add the complete email address here (and not just 'xyz@' or 'xyz'). |
| 24 PUBLIC_API_OWNERS = ( | 25 PUBLIC_API_OWNERS = ( |
| 25 'reed@chromium.org', | 26 'reed@chromium.org', |
| 26 'reed@google.com', | 27 'reed@google.com', |
| 27 'bsalomon@chromium.org', | 28 'bsalomon@chromium.org', |
| 28 'bsalomon@google.com', | 29 'bsalomon@google.com', |
| 29 'djsollen@chromium.org', | 30 'djsollen@chromium.org', |
| 30 'djsollen@google.com', | 31 'djsollen@google.com', |
| 31 ) | 32 ) |
| 32 | 33 |
| 33 AUTHORS_FILE_NAME = 'AUTHORS' | 34 AUTHORS_FILE_NAME = 'AUTHORS' |
| 34 | 35 |
| 36 DOCS_PREVIEW_URL = 'https://skia.org/?cl=' | |
| 37 | |
| 35 | 38 |
| 36 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): | 39 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): |
| 37 """Checks that files end with atleast one \n (LF).""" | 40 """Checks that files end with atleast one \n (LF).""" |
| 38 eof_files = [] | 41 eof_files = [] |
| 39 for f in input_api.AffectedSourceFiles(source_file_filter): | 42 for f in input_api.AffectedSourceFiles(source_file_filter): |
| 40 contents = input_api.ReadFile(f, 'rb') | 43 contents = input_api.ReadFile(f, 'rb') |
| 41 # Check that the file ends in atleast one newline character. | 44 # Check that the file ends in atleast one newline character. |
| 42 if len(contents) > 1 and contents[-1:] != '\n': | 45 if len(contents) > 1 and contents[-1:] != '\n': |
| 43 eof_files.append(f.LocalPath()) | 46 eof_files.append(f.LocalPath()) |
| 44 | 47 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 break | 235 break |
| 233 | 236 |
| 234 if not lgtm_from_owner: | 237 if not lgtm_from_owner: |
| 235 results.append( | 238 results.append( |
| 236 output_api.PresubmitError( | 239 output_api.PresubmitError( |
| 237 'Since the CL is editing public API, you must have an LGTM from ' | 240 'Since the CL is editing public API, you must have an LGTM from ' |
| 238 'one of: %s' % str(PUBLIC_API_OWNERS))) | 241 'one of: %s' % str(PUBLIC_API_OWNERS))) |
| 239 return results | 242 return results |
| 240 | 243 |
| 241 | 244 |
| 245 def PostUploadHook(cl, change, output_api): | |
| 246 """git cl upload will call this hook after the issue is created/modified. | |
| 247 | |
| 248 This hook does the following: | |
| 249 * Adds a link to preview docs changes if there are any docs changes in the CL. | |
| 250 * Adds 'NOTRY=true' if the CL contains only docs changes. | |
| 251 """ | |
| 252 | |
| 253 results = [] | |
| 254 atleast_one_docs_change = False | |
| 255 all_docs_changes = True | |
| 256 for affected_file in change.AffectedFiles(): | |
| 257 affected_file_path = affected_file.LocalPath() | |
| 258 file_path, _ = os.path.splitext(affected_file_path) | |
| 259 if 'site' == file_path.split(os.path.sep)[0]: | |
| 260 atleast_one_docs_change = True | |
| 261 else: | |
| 262 all_docs_changes = False | |
|
borenet
2015/02/26 17:38:56
Nit: you could short-cut here to avoid having to l
rmistry
2015/02/26 18:09:39
Done.
| |
| 263 | |
| 264 issue = cl.issue | |
| 265 rietveld_obj = cl.RpcServer() | |
| 266 if issue and rietveld_obj: | |
| 267 original_description = rietveld_obj.get_description(issue) | |
| 268 new_description = original_description | |
| 269 | |
| 270 # If the change includes only doc changes then add NOTRY=true in the | |
| 271 # CL's description if it does not exist yet. | |
| 272 if all_docs_changes and not re.search( | |
| 273 r'^NOTRY=true$', original_description, re.M | re.I): | |
| 274 new_description += '\nNOTRY=true' | |
| 275 results.append( | |
| 276 output_api.PresubmitNotifyResult( | |
| 277 'This change has only doc changes. Automatically added ' | |
| 278 '\'NOTRY=true\' to the CL\'s description')) | |
| 279 | |
| 280 # If there is atleast one docs change then add preview link in the CL's | |
| 281 # description if it does not already exist there. | |
| 282 if atleast_one_docs_change and not re.search( | |
| 283 r'^DOCS_PREVIEW=.*', original_description, re.M | re.I): | |
| 284 # Automatically add a link to where the docs can be previewed. | |
| 285 new_description += '\nDOCS_PREVIEW= %s%s' % (DOCS_PREVIEW_URL, issue) | |
| 286 results.append( | |
| 287 output_api.PresubmitNotifyResult( | |
| 288 'Automatically added a link to preview the docs changes to the ' | |
| 289 'CL\'s description')) | |
| 290 | |
| 291 # If the description has changed update it. | |
| 292 if new_description != original_description: | |
| 293 rietveld_obj.update_description(issue, new_description) | |
| 294 | |
| 295 return results | |
| 296 | |
| 297 | |
| 242 def CheckChangeOnCommit(input_api, output_api): | 298 def CheckChangeOnCommit(input_api, output_api): |
| 243 """Presubmit checks for the change on commit. | 299 """Presubmit checks for the change on commit. |
| 244 | 300 |
| 245 The following are the presubmit checks: | 301 The following are the presubmit checks: |
| 246 * Check change has one and only one EOL. | 302 * Check change has one and only one EOL. |
| 247 * Ensures that the Skia tree is open in | 303 * Ensures that the Skia tree is open in |
| 248 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' | 304 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' |
| 249 state and an error if it is in 'Closed' state. | 305 state and an error if it is in 'Closed' state. |
| 250 """ | 306 """ |
| 251 results = [] | 307 results = [] |
| 252 results.extend(_CommonChecks(input_api, output_api)) | 308 results.extend(_CommonChecks(input_api, output_api)) |
| 253 results.extend( | 309 results.extend( |
| 254 _CheckTreeStatus(input_api, output_api, json_url=( | 310 _CheckTreeStatus(input_api, output_api, json_url=( |
| 255 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 311 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
| 256 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 312 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
| 257 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 313 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
| 258 return results | 314 return results |
| OLD | NEW |