Sylvain Defresne | fcda19f | 2017-06-27 10:14:01 | [diff] [blame] | 1 | # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Presubmit script for ios. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details about the presubmit API built into depot_tools. |
| 9 | """ |
| 10 | |
| 11 | TODO_PATTERN = r'TO[D]O\(([^\)]*)\)' |
| 12 | CRBUG_PATTERN = r'crbug\.com/\d+$' |
| 13 | |
| 14 | def _CheckBugInToDo(input_api, output_api): |
| 15 | """ Checks whether TODOs in ios code are identified by a bug number.""" |
| 16 | todo_regex = input_api.re.compile(TODO_PATTERN) |
| 17 | crbug_regex = input_api.re.compile(CRBUG_PATTERN) |
| 18 | |
| 19 | errors = [] |
| 20 | for f in input_api.AffectedFiles(): |
| 21 | for line_num, line in f.ChangedContents(): |
| 22 | todo_match = todo_regex.search(line) |
| 23 | if not todo_match: |
| 24 | continue |
| 25 | crbug_match = crbug_regex.match(todo_match.group(1)) |
| 26 | if not crbug_match: |
| 27 | errors.append('%s:%s' % (f.LocalPath(), line_num)) |
| 28 | if not errors: |
| 29 | return [] |
| 30 | |
| 31 | plural_suffix = '' if len(errors) == 1 else 's' |
| 32 | error_message = '\n'.join([ |
| 33 | 'Found TO''DO%(plural)s without bug number%(plural)s (expected format is ' |
| 34 | '\"TO''DO(crbug.com/######)\":' % {'plural': plural_suffix} |
| 35 | ] + errors) + '\n' |
| 36 | |
| 37 | return [output_api.PresubmitError(error_message)] |
| 38 | |
| 39 | |
| 40 | def CheckChangeOnUpload(input_api, output_api): |
| 41 | results = [] |
| 42 | results.extend(_CheckBugInToDo(input_api, output_api)) |
| 43 | return results |
Misha Efimov | 015b1d8 | 2017-10-18 18:49:59 | [diff] [blame] | 44 | |
| 45 | def PostUploadHook(cl, change, output_api): |
| 46 | """git cl upload will call this hook after the issue is created/modified. |
| 47 | |
| 48 | This hook adds an extra try bot to the CL description in order to run Cronet |
Menglu Huang | a7e41d21 | 2017-11-09 18:30:12 | [diff] [blame] | 49 | and EarlGrey tests in addition to CQ try bots. |
Misha Efimov | 015b1d8 | 2017-10-18 18:49:59 | [diff] [blame] | 50 | """ |
| 51 | |
Menglu Huang | a7e41d21 | 2017-11-09 18:30:12 | [diff] [blame] | 52 | # TODO(crbug.com/712733): Remove ios-simulator-cronet once Cronet bots are |
| 53 | # deployed on CQ. |
| 54 | # TODO(crbug.com/782735): Remove ios-simulator-full-configs once EarlGrey |
| 55 | # bots are deployed on CQ. |
| 56 | try_bots = ['master.tryserver.chromium.mac:ios-simulator-cronet', |
| 57 | 'master.tryserver.chromium.mac:ios-simulator-full-configs'] |
Misha Efimov | 015b1d8 | 2017-10-18 18:49:59 | [diff] [blame] | 58 | |
| 59 | return output_api.EnsureCQIncludeTrybotsAreAdded( |
Menglu Huang | a7e41d21 | 2017-11-09 18:30:12 | [diff] [blame] | 60 | cl, try_bots, 'Automatically added Cronet and EarlGrey trybots to' |
| 61 | 'run tests on CQ.') |