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,
@ -115,17 +118,25 @@ class GiteaStatusPush(http.HttpStatusPushBase):
if 'repository_name' in props: if 'repository_name' in props:
repository_name = props['repository_name'] repository_name = props['repository_name']
else: else:
log.msg( match = re.match(self.ssh_url_match, sourcestamp['repository'])
"Could not send status, " if match is not None:
"build has no repository_name property for Gitea.") repository_name = match.group("repo_name")
continue else:
log.msg(
"Could not send status, "
"build has no repository_name property for Gitea.")
continue
if 'owner' in props: if 'owner' in props:
repository_owner = props['owner'] repository_owner = props['owner']
else: else:
log.msg( match = re.match(self.ssh_url_match, sourcestamp['repository'])
"Could not send status, " if match is not None:
"build has no owner property for Gitea.") repository_owner = match.group("owner")
continue else:
log.msg(
"Could not send status, "
"build has no owner property for Gitea.")
continue
try: try:
sha = unicode2NativeString(sha) sha = unicode2NativeString(sha)
state = unicode2NativeString(state) state = unicode2NativeString(state)

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()