Added owner and repo name detection in ssh url

This commit is contained in:
Marvin Pohl 2018-09-27 20:12:09 +02:00
parent 4f66ddc5c3
commit 4661da0060
2 changed files with 33 additions and 8 deletions

View File

@ -19,10 +19,13 @@ from buildbot.reporters import http
from buildbot.util import httpclientservice from buildbot.util import httpclientservice
from buildbot.util import unicode2NativeString from buildbot.util import unicode2NativeString
import re
class GiteaStatusPush(http.HttpStatusPushBase): class GiteaStatusPush(http.HttpStatusPushBase):
name = "GiteaStatusPush" name = "GiteaStatusPush"
neededDetails = dict(wantProperties=True) neededDetails = dict(wantProperties=True)
ssh_url_match = re.compile(r"(ssh://)?[\w+\-\_]+@[\w+\.\-\_]:?\d*/(?P<owner>[\w_\-\.]+)/(?P<repo_name>[\w_\-\.]+)\.git")
@defer.inlineCallbacks @defer.inlineCallbacks
def reconfigService(self, baseURL, token, def reconfigService(self, baseURL, token,
@ -114,6 +117,10 @@ class GiteaStatusPush(http.HttpStatusPushBase):
sha = sourcestamp['revision'] sha = sourcestamp['revision']
if 'repository_name' in props: if 'repository_name' in props:
repository_name = props['repository_name'] repository_name = props['repository_name']
else:
match = re.match(self.ssh_url_match, sourcestamp['repository'])
if match is not None:
repository_name = match.group("repo_name")
else: else:
log.msg( log.msg(
"Could not send status, " "Could not send status, "
@ -121,6 +128,10 @@ class GiteaStatusPush(http.HttpStatusPushBase):
continue continue
if 'owner' in props: if 'owner' in props:
repository_owner = props['owner'] repository_owner = props['owner']
else:
match = re.match(self.ssh_url_match, sourcestamp['repository'])
if match is not None:
repository_owner = match.group("owner")
else: else:
log.msg( log.msg(
"Could not send status, " "Could not send status, "

View File

@ -102,6 +102,20 @@ class TestGiteaStatusPush(
build['complete'] = False build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build) self.sp.buildStarted(("build", 20, "started"), build)
@defer.inlineCallbacks
def test_sshurl_noprops(self):
self.TEST_REPO = u'git@gitea:buildbot/buildbot.git'
build = yield self.setupBuildResults(SUCCESS)
# we make sure proper calls to txrequests have been made
self._http.expect(
'post',
'/api/v1/repos/buildbot/buildbot/statuses/d34db33fd43db33f',
json={'state': 'pending',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build started.', 'name': 'buildbot/Builder0'})
build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_noowner(self): def test_noowner(self):
self.setUpLogging() self.setUpLogging()