blob: 5628ad703f64b4751876b977b21c8354e4fa5e23 [file] [log] [blame]
Sylvain Defresnefcda19f2017-06-27 10:14:011# 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
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
10
11TODO_PATTERN = r'TO[D]O\(([^\)]*)\)'
12CRBUG_PATTERN = r'crbug\.com/\d+$'
13
14def _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
40def CheckChangeOnUpload(input_api, output_api):
41 results = []
42 results.extend(_CheckBugInToDo(input_api, output_api))
43 return results
Misha Efimov015b1d82017-10-18 18:49:5944
45def 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 Huanga7e41d212017-11-09 18:30:1249 and EarlGrey tests in addition to CQ try bots.
Misha Efimov015b1d82017-10-18 18:49:5950 """
51
Menglu Huanga7e41d212017-11-09 18:30:1252 # 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 Efimov015b1d82017-10-18 18:49:5958
59 return output_api.EnsureCQIncludeTrybotsAreAdded(
Menglu Huanga7e41d212017-11-09 18:30:1260 cl, try_bots, 'Automatically added Cronet and EarlGrey trybots to'
61 'run tests on CQ.')