Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import re | |
| 6 import urlparse | |
| 7 | |
| 5 from recipe_engine import recipe_test_api | 8 from recipe_engine import recipe_test_api |
| 6 | 9 |
| 7 class PropertiesTestApi(recipe_test_api.RecipeTestApi): | 10 class PropertiesTestApi(recipe_test_api.RecipeTestApi): |
| 8 def __call__(self, **kwargs): | 11 def __call__(self, **kwargs): |
| 9 ret = self.test(None) | 12 ret = self.test(None) |
| 10 ret.properties.update(kwargs) | 13 ret.properties.update(kwargs) |
| 11 return ret | 14 return ret |
| 12 | 15 |
| 13 def generic(self, **kwargs): | 16 def generic(self, **kwargs): |
| 14 """ | 17 """ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 """ | 50 """ |
| 48 ret = self.generic( | 51 ret = self.generic( |
| 49 branch='master', | 52 branch='master', |
| 50 project='', | 53 project='', |
| 51 repository='https://chromium.googlesource.com/chromium/src.git', | 54 repository='https://chromium.googlesource.com/chromium/src.git', |
| 52 revision='c14d891d44f0afff64e56ed7c9702df1d807b1ee', | 55 revision='c14d891d44f0afff64e56ed7c9702df1d807b1ee', |
| 53 ) | 56 ) |
| 54 ret.properties.update(kwargs) | 57 ret.properties.update(kwargs) |
| 55 return ret | 58 return ret |
| 56 | 59 |
| 60 def _gerrit_tryserver(self, **kwargs): | |
| 61 # Call it through self.tryserver with (gerrit_project='infra/infra'). | |
| 62 project = kwargs.pop('gerrit_project') | |
| 63 gerrit_url = kwargs.pop('gerrit_url', None) | |
| 64 git_url = kwargs.pop('git_url', None) | |
| 65 if not gerrit_url and not git_url: | |
| 66 gerrit_url = 'https://chromium-review.googlesource.com' | |
| 67 git_url = 'https://chromium.googlesource.com/' + project | |
| 68 elif gerrit_url and not git_url: | |
| 69 parsed = list(urlparse.urlparse(gerrit_url)) | |
| 70 m = re.match(r'^((\w+)(-\w+)*)-review.googlesource.com$', parsed[1]) | |
| 71 if not m: # pragma: no cover | |
| 72 raise AssertionError('Can\'t guess git_url from gerrit_url "%s", ' | |
| 73 'specify it as extra kwarg' % parsed[1]) | |
| 74 parsed[1] = m.group(1) + '.googlesource.com' | |
| 75 parsed[2] = project | |
| 76 git_url = urlparse.urlunparse(parsed) | |
| 77 elif git_url and not gerrit_url: | |
| 78 parsed = list(urlparse.urlparse(git_url)) | |
| 79 m = re.match(r'^((\w+)(-\w+)*).googlesource.com$', parsed[1]) | |
| 80 if not m: # pragma: no cover | |
| 81 raise AssertionError('Can\'t guess gerrit_url from git_url "%s", ' | |
| 82 'specify it as extra kwarg' % parsed[1]) | |
| 83 parsed[1] = m.group(1) + '-review.googlesource.com' | |
| 84 gerrit_url = urlparse.urlunparse(parsed[:2] + [''] * len(parsed[2:])) | |
| 85 assert project | |
| 86 assert git_url | |
| 87 assert gerrit_url | |
| 88 # Pop old style values from kwargs. | |
| 89 patch_issue = int(kwargs.pop('issue', 456789)) | |
| 90 patch_set = int(kwargs.pop('patchset', 12)) | |
| 91 # Note that new Gerrit patch properties all start with 'patch_' prefix. | |
| 92 ret = self.generic( | |
| 93 patch_storage='gerrit', | |
| 94 patch_gerrit_url=gerrit_url, | |
| 95 patch_project=project, | |
| 96 patch_branch='master', | |
| 97 patch_issue=patch_issue, | |
| 98 patch_set=patch_set, | |
| 99 patch_repository_url=git_url, | |
| 100 patch_ref='refs/changes/%2d/%d/%d' % ( | |
| 101 patch_issue % 100, patch_issue, patch_set) | |
| 102 ) | |
| 103 ret.properties.update(kwargs) | |
| 104 return ret | |
| 105 | |
| 57 def tryserver(self, **kwargs): | 106 def tryserver(self, **kwargs): |
| 58 """ | 107 """ |
| 59 Merge kwargs into a typical buildbot properties blob for a job fired off | 108 Merge kwargs into a typical buildbot properties blob for a job fired off |
| 60 by a rietveld tryjob on the tryserver, and return the blob. | 109 by a rietveld tryjob on the tryserver, and return the blob. |
| 110 | |
| 111 If gerrit_project is given, generated properties for tryjobs for Gerrit | |
| 112 patches as if they were scheduled by CQ. In this case, gerrit_url and | |
| 113 git_url could be used to customize expectations. | |
| 61 """ | 114 """ |
| 62 ret = self.generic( | 115 if kwargs.get('gerrit_project') is not None: |
| 63 branch='', | 116 return self._gerrit_tryserver(**kwargs) |
| 64 issue=12853011, | 117 else: |
|
Paweł Hajdan Jr.
2016/10/25 10:58:54
nit: No need for "else" after return.
tandrii(chromium)
2016/10/25 12:38:31
Done.
| |
| 65 patchset=1, | 118 ret = self.generic( |
| 66 project='chrome', | 119 branch='', |
| 67 repository='', | 120 issue=12853011, |
| 68 requester='commit-bot@chromium.org', | 121 patchset=1, |
| 69 revision='HEAD', | 122 project='chrome', |
| 70 rietveld='https://codereview.chromium.org', | 123 repository='', |
| 71 patch_project='chromium', | 124 requester='commit-bot@chromium.org', |
| 72 ) | 125 revision='HEAD', |
| 126 rietveld='https://codereview.chromium.org', | |
| 127 patch_project='chromium', | |
| 128 ) | |
| 73 ret.properties.update(kwargs) | 129 ret.properties.update(kwargs) |
| 74 return ret | 130 return ret |
| 75 | 131 |
| 76 def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): | 132 def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): |
| 77 """ | 133 """ |
| 134 DEPRECATED. Use tryserver(gerrit_project='infra/infra') instead. | |
| 135 | |
| 78 Merge kwargs into a typical buildbot properties blob for a job fired off | 136 Merge kwargs into a typical buildbot properties blob for a job fired off |
| 79 by a gerrit tryjob on the tryserver, and return the blob. | 137 by a gerrit tryjob on the tryserver, and return the blob. |
| 80 | 138 |
| 81 Arguments: | 139 Arguments: |
| 82 full_project_name: (required) name of the project in Gerrit. | 140 full_project_name: (required) name of the project in Gerrit. |
| 83 gerrit_host: hostname of the gerrit server. | 141 gerrit_host: hostname of the gerrit server. |
| 84 Example: chromium-review.googlesource.com. | 142 Example: chromium-review.googlesource.com. |
| 85 """ | 143 """ |
| 144 # TODO(tandrii): remove this method. | |
| 86 gerrit_host = gerrit_host or 'chromium-review.googlesource.com' | 145 gerrit_host = gerrit_host or 'chromium-review.googlesource.com' |
| 87 parts = gerrit_host.split('.') | 146 parts = gerrit_host.split('.') |
| 88 assert parts[0].endswith('-review') | 147 assert parts[0].endswith('-review') |
| 89 parts[0] = parts[0][:-len('-review')] | 148 parts[0] = parts[0][:-len('-review')] |
| 90 repository = 'https://%s/%s' % ('.'.join(parts), full_project_name) | 149 repository = 'https://%s/%s' % ('.'.join(parts), full_project_name) |
| 91 | 150 |
| 92 ret = self.generic( | 151 ret = self.generic( |
| 93 branch='', | 152 branch='', |
| 94 category='cq', | 153 category='cq', |
| 95 gerrit='https://%s' % gerrit_host, | 154 gerrit='https://%s' % gerrit_host, |
| 96 patch_storage='gerrit', | 155 patch_storage='gerrit', |
| 97 project=full_project_name, | 156 project=full_project_name, |
| 98 patch_project=full_project_name, | 157 patch_project=full_project_name, |
| 99 reason='CQ', | 158 reason='CQ', |
| 100 repository=repository, | 159 repository=repository, |
| 101 requester='commit-bot@chromium.org', | 160 requester='commit-bot@chromium.org', |
| 102 revision='HEAD', | 161 revision='HEAD', |
| 103 ) | 162 ) |
| 104 ret.properties.update({ | 163 ret.properties.update({ |
| 105 'event.change.id': u'%s~master~Ideadbeaf' % | 164 'event.change.id': u'%s~master~Ideadbeaf' % |
| 106 (full_project_name.replace('/', '%2F')), | 165 (full_project_name.replace('/', '%2F')), |
| 107 'event.change.number': 338811, | 166 'event.change.number': 338811, |
| 108 'event.change.url': u'https://%s/#/c/338811' % gerrit_host, | 167 'event.change.url': u'https://%s/#/c/338811' % gerrit_host, |
| 109 'event.patchSet.ref': u'refs/changes/11/338811/3', | 168 'event.patchSet.ref': u'refs/changes/11/338811/3', |
| 110 }) | 169 }) |
| 111 ret.properties.update(kwargs) | 170 ret.properties.update(kwargs) |
| 112 return ret | 171 return ret |
| OLD | NEW |