Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: PRESUBMIT.py

Issue 960203002: Automatically add a docs preview link and NOTRY=true when there are only docs changes (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Short circuit the loop Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | codereview.settings » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
263 if atleast_one_docs_change and not all_docs_changes:
264 break
265
266 issue = cl.issue
267 rietveld_obj = cl.RpcServer()
268 if issue and rietveld_obj:
269 original_description = rietveld_obj.get_description(issue)
270 new_description = original_description
271
272 # If the change includes only doc changes then add NOTRY=true in the
273 # CL's description if it does not exist yet.
274 if all_docs_changes and not re.search(
275 r'^NOTRY=true$', original_description, re.M | re.I):
276 new_description += '\nNOTRY=true'
277 results.append(
278 output_api.PresubmitNotifyResult(
279 'This change has only doc changes. Automatically added '
280 '\'NOTRY=true\' to the CL\'s description'))
281
282 # If there is atleast one docs change then add preview link in the CL's
283 # description if it does not already exist there.
284 if atleast_one_docs_change and not re.search(
285 r'^DOCS_PREVIEW=.*', original_description, re.M | re.I):
286 # Automatically add a link to where the docs can be previewed.
287 new_description += '\nDOCS_PREVIEW= %s%s' % (DOCS_PREVIEW_URL, issue)
288 results.append(
289 output_api.PresubmitNotifyResult(
290 'Automatically added a link to preview the docs changes to the '
291 'CL\'s description'))
292
293 # If the description has changed update it.
294 if new_description != original_description:
295 rietveld_obj.update_description(issue, new_description)
296
297 return results
298
299
242 def CheckChangeOnCommit(input_api, output_api): 300 def CheckChangeOnCommit(input_api, output_api):
243 """Presubmit checks for the change on commit. 301 """Presubmit checks for the change on commit.
244 302
245 The following are the presubmit checks: 303 The following are the presubmit checks:
246 * Check change has one and only one EOL. 304 * Check change has one and only one EOL.
247 * Ensures that the Skia tree is open in 305 * Ensures that the Skia tree is open in
248 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' 306 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. 307 state and an error if it is in 'Closed' state.
250 """ 308 """
251 results = [] 309 results = []
252 results.extend(_CommonChecks(input_api, output_api)) 310 results.extend(_CommonChecks(input_api, output_api))
253 results.extend( 311 results.extend(
254 _CheckTreeStatus(input_api, output_api, json_url=( 312 _CheckTreeStatus(input_api, output_api, json_url=(
255 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) 313 SKIA_TREE_STATUS_URL + '/banner-status?format=json')))
256 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) 314 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api))
257 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) 315 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api))
258 return results 316 return results
OLDNEW
« no previous file with comments | « no previous file | codereview.settings » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698