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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/PRESUBMIT.py
diff --git a/chrome/browser/resources/PRESUBMIT.py b/chrome/browser/resources/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..9ec83d135184967b5363a4124f72932a8e81cab5
--- /dev/null
+++ b/chrome/browser/resources/PRESUBMIT.py
@@ -0,0 +1,47 @@
+# 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.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Presubmit script for HTML files in .
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
+for more details about the presubmit API built into gcl.
+"""
+
+def CheckUserActionUpdate(input_api, output_api):
+ print "here"
+ """Checks if any new user action has been added."""
+ if any('actions.xml' == input_api.os_path.basename(f) for f in
+ input_api.LocalPaths()):
+ # If actions.xml is already included in the changelist, the PRESUBMIT
+ # for actions.xml will do a more complete presubmit check.
+ return []
+
+ file_filter = lambda f: f.LocalPath().endswith(('.html'))
+ 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
+ current_actions = None
+ for f in input_api.AffectedFiles(file_filter=file_filter):
+ for line_num, line in f.ChangedContents():
+ match = input_api.re.search(action_re, line)
+ if match:
+ # Loads contents in tools/metrics/actions/actions.xml to memory. It's
+ # loaded only once.
+ if not current_actions:
+ with open('../../../tools/metrics/actions/actions.xml') as actions_f:
+ current_actions = actions_f.read()
+ # Search for the matched user action name in |current_actions|.
+ for action_name in match.groups():
+ action = 'name="{0}"'.format(action_name)
+ if action not in current_actions:
+ return [output_api.PresubmitPromptWarning(
+ 'File %s line %d: %s is missing in '
+ 'tools/metrics/actions/actions.xml. Please run '
+ 'tools/metrics/actions/extract_actions.py to update.'
+ % (f.LocalPath(), line_num, action_name))]
+ return []
+
+def CheckChangeOnUpload(input_api, output_api):
+ return CheckUserActionUpdate(input_api, output_api)
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ return CheckUserActionUpdate(input_api, output_api)

Powered by Google App Engine
This is Rietveld 408576698