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 urlparse | |
|
Michael Achenbach
2016/10/24 09:24:34
nit: sort
tandrii(chromium)
2016/10/24 11:23:17
Done.
| |
| 6 import re | |
| 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('^((\w+)(-\w+)*)-review.googlesource.com$', parsed[1]) | |
|
Michael Achenbach
2016/10/24 09:24:34
Don't you need an r'' ?
Michael Achenbach
2016/10/24 09:24:34
Maybe mark the non-capturing groups as you don't n
tandrii(chromium)
2016/10/24 11:23:17
I don't understand why. I take 1st group, which is
tandrii(chromium)
2016/10/24 11:23:17
I do, and I'd swear it was there. How does it even
Michael Achenbach
2016/10/24 11:51:51
This would be the syntax, e.g. see:
https://docs.p
| |
| 71 assert m, ('Can\'t guess git_url from gerrit_url "%s", ' | |
|
martiniss
2016/10/24 16:48:21
nit: asserts can be disabled in python, turn this
tandrii(chromium)
2016/10/24 18:02:19
I know, but
a) this is a test expectation, so disa
| |
| 72 'specify it as extra kwarg' % parsed[1]) | |
| 73 parsed[1] = m.group(1) + '.googlesource.com' | |
| 74 parsed[2] = project | |
| 75 git_url = urlparse.urlunparse(parsed) | |
| 76 elif git_url and not gerrit_url: | |
| 77 parsed = list(urlparse.urlparse(git_url)) | |
| 78 m = re.match('^((\w+)(-\w+)*).googlesource.com$', parsed[1]) | |
| 79 assert m, ('Can\'t guess gerrit_url from git_url "%s", ' | |
| 80 ', specify it as extra kwarg' % parsed[1]) | |
|
Michael Achenbach
2016/10/24 09:24:34
nit: double comma
| |
| 81 parsed[1] = m.group(1) + '.googlesource.com' | |
|
Michael Achenbach
2016/10/24 09:24:34
Don't you need to add "-review" in this case? Thou
tandrii(chromium)
2016/10/24 11:23:17
Yep, fixed.
| |
| 82 gerrit_url = urlparse.urlunparse(parsed[:2] + [''] * len(parsed[2:])) | |
| 83 assert project | |
| 84 assert git_url | |
| 85 assert gerrit_url | |
| 86 # Pop old style values from kwargs. | |
| 87 patch_issue = int(kwargs.pop('issue', 456789)) | |
| 88 patch_set = int(kwargs.pop('patchset', 12)) | |
| 89 # Note that new Gerrit patch properties all start with 'patch_' prefix. | |
| 90 ret = self.generic( | |
| 91 patch_storage='gerrit', | |
| 92 patch_gerrit_url=gerrit_url, | |
|
Michael Achenbach
2016/10/24 09:24:34
Why not use equal names (e.g. patch_gerrit_url for
tandrii(chromium)
2016/10/24 11:23:17
I was and am undecided on this one. I didn't want
Michael Achenbach
2016/10/24 11:51:51
Ack. Your choice. I don't have a strong opinion he
| |
| 93 patch_project=project, | |
| 94 patch_branch='master', | |
| 95 patch_issue=patch_issue, | |
| 96 patch_set=patch_set, | |
| 97 patch_repository_url=git_url, | |
| 98 patch_ref='refs/changes/%2d/%d/%d' % ( | |
| 99 patch_issue % 100, patch_issue, patch_set) | |
| 100 ) | |
| 101 ret.properties.update(kwargs) | |
| 102 return ret | |
| 103 | |
| 57 def tryserver(self, **kwargs): | 104 def tryserver(self, **kwargs): |
| 58 """ | 105 """ |
| 59 Merge kwargs into a typical buildbot properties blob for a job fired off | 106 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. | 107 by a rietveld tryjob on the tryserver, and return the blob. |
| 108 | |
| 109 If gerrit_project is given, generated properties for tryjobs for Gerrit | |
| 110 patches as if they were scheduled by CQ. In this case, gerrit_url and | |
| 111 git_url could be used to customize expectations. | |
| 61 """ | 112 """ |
| 62 ret = self.generic( | 113 if kwargs.get('gerrit_project') is not None: |
| 63 branch='', | 114 return self._gerrit_tryserver(**kwargs) |
| 64 issue=12853011, | 115 else: |
| 65 patchset=1, | 116 ret = self.generic( |
| 66 project='chrome', | 117 branch='', |
| 67 repository='', | 118 issue=12853011, |
| 68 requester='commit-bot@chromium.org', | 119 patchset=1, |
| 69 revision='HEAD', | 120 project='chrome', |
| 70 rietveld='https://codereview.chromium.org', | 121 repository='', |
| 71 patch_project='chromium', | 122 requester='commit-bot@chromium.org', |
| 72 ) | 123 revision='HEAD', |
| 124 rietveld='https://codereview.chromium.org', | |
| 125 patch_project='chromium', | |
| 126 ) | |
| 73 ret.properties.update(kwargs) | 127 ret.properties.update(kwargs) |
| 74 return ret | 128 return ret |
| 75 | 129 |
| 76 def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): | 130 def tryserver_gerrit(self, full_project_name, gerrit_host=None, **kwargs): |
| 77 """ | 131 """ |
| 132 DEPRECATED. Use tryserver(gerrit_project='infra/infra') instead. | |
| 133 | |
| 78 Merge kwargs into a typical buildbot properties blob for a job fired off | 134 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. | 135 by a gerrit tryjob on the tryserver, and return the blob. |
| 80 | 136 |
| 81 Arguments: | 137 Arguments: |
| 82 full_project_name: (required) name of the project in Gerrit. | 138 full_project_name: (required) name of the project in Gerrit. |
| 83 gerrit_host: hostname of the gerrit server. | 139 gerrit_host: hostname of the gerrit server. |
| 84 Example: chromium-review.googlesource.com. | 140 Example: chromium-review.googlesource.com. |
| 85 """ | 141 """ |
| 142 # TODO(tandrii): remove this method. | |
| 86 gerrit_host = gerrit_host or 'chromium-review.googlesource.com' | 143 gerrit_host = gerrit_host or 'chromium-review.googlesource.com' |
| 87 parts = gerrit_host.split('.') | 144 parts = gerrit_host.split('.') |
| 88 assert parts[0].endswith('-review') | 145 assert parts[0].endswith('-review') |
| 89 parts[0] = parts[0][:-len('-review')] | 146 parts[0] = parts[0][:-len('-review')] |
| 90 repository = 'https://%s/%s' % ('.'.join(parts), full_project_name) | 147 repository = 'https://%s/%s' % ('.'.join(parts), full_project_name) |
| 91 | 148 |
| 92 ret = self.generic( | 149 ret = self.generic( |
| 93 branch='', | 150 branch='', |
| 94 category='cq', | 151 category='cq', |
| 95 gerrit='https://%s' % gerrit_host, | 152 gerrit='https://%s' % gerrit_host, |
| 96 patch_storage='gerrit', | 153 patch_storage='gerrit', |
| 97 project=full_project_name, | 154 project=full_project_name, |
| 98 patch_project=full_project_name, | 155 patch_project=full_project_name, |
| 99 reason='CQ', | 156 reason='CQ', |
| 100 repository=repository, | 157 repository=repository, |
| 101 requester='commit-bot@chromium.org', | 158 requester='commit-bot@chromium.org', |
| 102 revision='HEAD', | 159 revision='HEAD', |
| 103 ) | 160 ) |
| 104 ret.properties.update({ | 161 ret.properties.update({ |
| 105 'event.change.id': u'%s~master~Ideadbeaf' % | 162 'event.change.id': u'%s~master~Ideadbeaf' % |
| 106 (full_project_name.replace('/', '%2F')), | 163 (full_project_name.replace('/', '%2F')), |
| 107 'event.change.number': 338811, | 164 'event.change.number': 338811, |
| 108 'event.change.url': u'https://%s/#/c/338811' % gerrit_host, | 165 'event.change.url': u'https://%s/#/c/338811' % gerrit_host, |
| 109 'event.patchSet.ref': u'refs/changes/11/338811/3', | 166 'event.patchSet.ref': u'refs/changes/11/338811/3', |
| 110 }) | 167 }) |
| 111 ret.properties.update(kwargs) | 168 ret.properties.update(kwargs) |
| 112 return ret | 169 return ret |
| OLD | NEW |