| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Presubmit script for HTML files in chrome/browser/resources. | 5 """Presubmit script for files in chrome/browser/resources. |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import re |
| 12 |
| 13 |
| 11 ACTION_XML_PATH = '../../../tools/metrics/actions/actions.xml' | 14 ACTION_XML_PATH = '../../../tools/metrics/actions/actions.xml' |
| 12 | 15 |
| 16 |
| 13 def CheckUserActionUpdate(input_api, output_api, action_xml_path): | 17 def CheckUserActionUpdate(input_api, output_api, action_xml_path): |
| 14 """Checks if any new user action has been added.""" | 18 """Checks if any new user action has been added.""" |
| 15 if any('actions.xml' == input_api.os_path.basename(f) for f in | 19 if any('actions.xml' == input_api.os_path.basename(f) for f in |
| 16 input_api.change.LocalPaths()): | 20 input_api.change.LocalPaths()): |
| 17 # If actions.xml is already included in the changelist, the PRESUBMIT | 21 # If actions.xml is already included in the changelist, the PRESUBMIT |
| 18 # for actions.xml will do a more complete presubmit check. | 22 # for actions.xml will do a more complete presubmit check. |
| 19 return [] | 23 return [] |
| 20 | 24 |
| 21 file_filter = lambda f: f.LocalPath().endswith('.html') | 25 file_filter = lambda f: f.LocalPath().endswith('.html') |
| 22 action_re = r'(^|\s+)metric\s*=\s*"([^ ]*)"' | 26 action_re = r'(^|\s+)metric\s*=\s*"([^ ]*)"' |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return (match and | 90 return (match and |
| 87 any(input_api.re.search(type_re, match.group(i)) for i in (1, 3))) | 91 any(input_api.re.search(type_re, match.group(i)) for i in (1, 3))) |
| 88 | 92 |
| 89 | 93 |
| 90 def CheckChangeOnUpload(input_api, output_api): | 94 def CheckChangeOnUpload(input_api, output_api): |
| 91 return CheckUserActionUpdate(input_api, output_api, ACTION_XML_PATH) | 95 return CheckUserActionUpdate(input_api, output_api, ACTION_XML_PATH) |
| 92 | 96 |
| 93 | 97 |
| 94 def CheckChangeOnCommit(input_api, output_api): | 98 def CheckChangeOnCommit(input_api, output_api): |
| 95 return CheckUserActionUpdate(input_api, output_api, ACTION_XML_PATH) | 99 return CheckUserActionUpdate(input_api, output_api, ACTION_XML_PATH) |
| 100 |
| 101 |
| 102 def PostUploadHook(cl, change, output_api): |
| 103 rietveld_obj = cl.RpcServer() |
| 104 description = rietveld_obj.get_description(cl.issue) |
| 105 |
| 106 existing_bots = (change.CQ_INCLUDE_TRYBOTS or '').split(';') |
| 107 clean_bots = set(filter(None, map(lambda s: s.strip(), existing_bots))) |
| 108 new_bots = clean_bots | set(['tryserver.chromium.linux:closure_compilation']) |
| 109 new_tag = 'CQ_INCLUDE_TRYBOTS=%s' % ';'.join(new_bots) |
| 110 |
| 111 if clean_bots: |
| 112 tag_reg = '^CQ_INCLUDE_TRYBOTS=.*$' |
| 113 new_description = re.sub(tag_reg, new_tag, description, flags=re.M | re.I) |
| 114 else: |
| 115 new_description = description + '\n' + new_tag |
| 116 |
| 117 if new_description == description: |
| 118 return [] |
| 119 |
| 120 rietveld_obj.update_description(cl.issue, new_description) |
| 121 return [output_api.PresubmitNotifyResult( |
| 122 'Automatically added optional Closure bots to run on CQ.')] |
| OLD | NEW |