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

Side by Side Diff: chrome/browser/resources/PRESUBMIT.py

Issue 719463003: Presubmit checks for user actions intorduced in HTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
Alexei Svitkine (slow) 2014/11/11 20:36:41 Nit: "Copyright 2014" (no (c))
gayane -on leave until 09-2017 2014/11/12 22:00:23 Done.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 """Presubmit script for HTML files in .
5
6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7 for more details about the presubmit API built into gcl.
8 """
9
10 def CheckUserActionUpdate(input_api, output_api):
11 print "here"
12 """Checks if any new user action has been added."""
13 if any('actions.xml' == input_api.os_path.basename(f) for f in
14 input_api.LocalPaths()):
15 # If actions.xml is already included in the changelist, the PRESUBMIT
16 # for actions.xml will do a more complete presubmit check.
17 return []
18
19 file_filter = lambda f: f.LocalPath().endswith(('.html'))
20 action_re = r'metric\s*=\s*"([^ ]*)"'
Alexei Svitkine (slow) 2014/11/11 20:36:41 Should we check for whitespace before the start of
gayane -on leave until 09-2017 2014/11/12 22:00:23 whitespaces or beginning of the line cases added t
21 current_actions = None
22 for f in input_api.AffectedFiles(file_filter=file_filter):
23 for line_num, line in f.ChangedContents():
24 match = input_api.re.search(action_re, line)
25 if match:
26 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
27 # loaded only once.
28 if not current_actions:
29 with open('../../../tools/metrics/actions/actions.xml') as actions_f:
30 current_actions = actions_f.read()
31 # Search for the matched user action name in |current_actions|.
32 for action_name in match.groups():
33 action = 'name="{0}"'.format(action_name)
34 if action not in current_actions:
35 return [output_api.PresubmitPromptWarning(
36 'File %s line %d: %s is missing in '
37 'tools/metrics/actions/actions.xml. Please run '
38 'tools/metrics/actions/extract_actions.py to update.'
39 % (f.LocalPath(), line_num, action_name))]
40 return []
41
42 def CheckChangeOnUpload(input_api, output_api):
43 return CheckUserActionUpdate(input_api, output_api)
44
45
46 def CheckChangeOnCommit(input_api, output_api):
47 return CheckUserActionUpdate(input_api, output_api)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698