blob: 6e96ceb0860c4978b7eb4b3f0db1e560db86fee7 [file] [log] [blame]
kjellander@webrtc.orgde2a76f2012-03-27 15:57:30 +00001# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS. All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
8
9def _LicenseHeader(input_api):
10 """Returns the license header regexp."""
kjellander@webrtc.org6307dbf2012-08-31 07:07:11 +000011 # Accept any year number from 2011 to the current year
12 current_year = int(input_api.time.strftime('%Y'))
13 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1)))
14 years_re = '(' + '|'.join(allowed_years) + ')'
kjellander@webrtc.orgde2a76f2012-03-27 15:57:30 +000015 license_header = (
16 r'.*? Copyright \(c\) %(year)s The WebRTC project authors\. '
17 r'All Rights Reserved\.\n'
18 r'.*?\n'
19 r'.*? Use of this source code is governed by a BSD-style license\n'
20 r'.*? that can be found in the LICENSE file in the root of the source\n'
21 r'.*? tree\. An additional intellectual property rights grant can be '
22 r'found\n'
23 r'.*? in the file PATENTS\. All contributing project authors may\n'
24 r'.*? be found in the AUTHORS file in the root of the source tree\.\n'
25 ) % {
kjellander@webrtc.org6307dbf2012-08-31 07:07:11 +000026 'year': years_re,
kjellander@webrtc.orgde2a76f2012-03-27 15:57:30 +000027 }
28 return license_header
29
30def _CommonChecks(input_api, output_api):
31 """Checks common to both upload and commit."""
32 results = []
33 results.extend(input_api.canned_checks.CheckLongLines(
phoglund@webrtc.org6d07ad92013-05-14 09:42:39 +000034 input_api, output_api, maxlen=80))
kjellander@webrtc.orgde2a76f2012-03-27 15:57:30 +000035 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
36 input_api, output_api))
37 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
38 input_api, output_api))
39 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
40 input_api, output_api))
41 results.extend(input_api.canned_checks.CheckLicense(
42 input_api, output_api, _LicenseHeader(input_api)))
43 return results
44
45def CheckChangeOnUpload(input_api, output_api):
46 results = []
47 results.extend(_CommonChecks(input_api, output_api))
48 return results
49
50def CheckChangeOnCommit(input_api, output_api):
51 results = []
52 results.extend(_CommonChecks(input_api, output_api))
53 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
54 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
55 input_api, output_api))
56 results.extend(input_api.canned_checks.CheckChangeHasDescription(
57 input_api, output_api))
58 results.extend(input_api.canned_checks.CheckChangeHasBugField(
59 input_api, output_api))
60 results.extend(input_api.canned_checks.CheckChangeHasTestField(
61 input_api, output_api))
62 return results