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

Side by Side Diff: third_party/cq_client/validate_config.py

Issue 1475033006: Updated cq_client (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Restore manual protobuf26 fixes Created 5 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """CQ config validation library.""" 6 """CQ config validation library."""
7 7
8 import argparse 8 import argparse
9 # This file was originally copied together with the cq_client library from the 9 # This file was originally copied together with the cq_client library from the
10 # internal commit_queue repository and then modified to import protobuf26 10 # internal commit_queue repository and then modified to import protobuf26
11 # instead of google.protobuf to prevent conflicts with a different version of 11 # instead of google.protobuf to prevent conflicts with a different version of
12 # google.protobuf that some users of depot_tools have installed. If you need to 12 # google.protobuf that some users of depot_tools have installed. If you need to
13 # update this file, please make similar changes again and add this comment back. 13 # update this file, please make similar changes again and add this comment back.
14 # More details on why we chose to rename the package can be found in the file 14 # More details on why we chose to rename the package can be found in the file
15 # depot_tools/third_party/protobuf26/README.chromium. 15 # depot_tools/third_party/protobuf26/README.chromium.
16 import protobuf26 as protobuf 16 import protobuf26 as protobuf
17 import logging 17 import logging
18 import re 18 import re
19 import sys 19 import sys
20 20
21 from cq_client import cq_pb2 21 from cq_client import cq_pb2
22 22
23 23
24 REQUIRED_FIELDS = [ 24 REQUIRED_FIELDS = [
25 'version', 25 'version',
26 'rietveld',
27 'rietveld.url',
28 'verifiers', 26 'verifiers',
29 'cq_name', 27 'cq_name',
30 ] 28 ]
31 29
32 LEGACY_FIELDS = [ 30 LEGACY_FIELDS = [
33 'svn_repo_url', 31 'svn_repo_url',
34 'server_hooks_missing',
35 'verifiers_with_patch',
36 ] 32 ]
37 33
38 EMAIL_REGEXP = '^[^@]+@[^@]+\.[^@]+$' 34 EMAIL_REGEXP = '^[^@]+@[^@]+\.[^@]+$'
39 35
40 36
41 def _HasField(message, field_path): 37 def _HasField(message, field_path):
42 """Checks that at least one field with given path exist in the proto message. 38 """Checks that at least one field with given path exist in the proto message.
43 39
44 This function correctly handles repeated fields and will make sure that each 40 This function correctly handles repeated fields and will make sure that each
45 repeated field will have required sub-path, e.g. if 'abc' is a repeated field 41 repeated field will have required sub-path, e.g. if 'abc' is a repeated field
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 Returns: 81 Returns:
86 True if the config is valid. 82 True if the config is valid.
87 """ 83 """
88 try: 84 try:
89 config = cq_pb2.Config() 85 config = cq_pb2.Config()
90 protobuf.text_format.Merge(cq_config, config) 86 protobuf.text_format.Merge(cq_config, config)
91 except protobuf.text_format.ParseError as e: 87 except protobuf.text_format.ParseError as e:
92 logging.error('Failed to parse config as protobuf:\n%s', e) 88 logging.error('Failed to parse config as protobuf:\n%s', e)
93 return False 89 return False
94 90
95 for fname in REQUIRED_FIELDS: 91 if _HasField(config, 'gerrit'):
92 if _HasField(config, 'rietveld'):
93 logging.error('gerrit and rietveld are not supported at the same time.')
94 return False
95 # TODO(tandrii): validate gerrit.
96 required_fields = REQUIRED_FIELDS + ['gerrit.cq_verified_label']
97 if _HasField(config, 'verifiers.reviewer_lgtm'):
98 logging.error('reviewer_lgtm verifier is not supported with Gerrit.')
99 return False
100 elif _HasField(config, 'rietveld'):
101 required_fields = REQUIRED_FIELDS + ['rietveld.url']
102 else:
103 logging.error('either rietveld gerrit are required fields.')
104 return False
105
106 for fname in required_fields:
96 if not _HasField(config, fname): 107 if not _HasField(config, fname):
97 logging.error('%s is a required field', fname) 108 logging.error('%s is a required field', fname)
98 return False 109 return False
99 110
100 for fname in LEGACY_FIELDS: 111 for fname in LEGACY_FIELDS:
101 if _HasField(config, fname): 112 if _HasField(config, fname):
102 logging.warn('%s is a legacy field', fname) 113 logging.warn('%s is a legacy field', fname)
103 114
104 115
105 for base in config.rietveld.project_bases: 116 for base in config.rietveld.project_bases:
106 try: 117 try:
107 re.compile(base) 118 re.compile(base)
108 except re.error: 119 except re.error:
109 logging.error('failed to parse "%s" in project_bases as a regexp', base) 120 logging.error('failed to parse "%s" in project_bases as a regexp', base)
110 return False 121 return False
111 122
112 # TODO(sergiyb): For each field, check valid values depending on its 123 # TODO(sergiyb): For each field, check valid values depending on its
113 # semantics, e.g. email addresses, regular expressions etc. 124 # semantics, e.g. email addresses, regular expressions etc.
114
115 return True 125 return True
OLDNEW
« third_party/cq_client/README.md ('K') | « third_party/cq_client/test/validate_config_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698