diff --git a/buildbot_gitea/reporter.py b/buildbot_gitea/reporter.py index ce887e1..f31d3c7 100644 --- a/buildbot_gitea/reporter.py +++ b/buildbot_gitea/reporter.py @@ -19,10 +19,13 @@ from buildbot.reporters import http from buildbot.util import httpclientservice from buildbot.util import unicode2NativeString +import re + class GiteaStatusPush(http.HttpStatusPushBase): name = "GiteaStatusPush" neededDetails = dict(wantProperties=True) + ssh_url_match = re.compile(r"(ssh://)?[\w+\-\_]+@[\w+\.\-\_]:?\d*/(?P[\w_\-\.]+)/(?P[\w_\-\.]+)\.git") @defer.inlineCallbacks def reconfigService(self, baseURL, token, @@ -115,17 +118,25 @@ class GiteaStatusPush(http.HttpStatusPushBase): if 'repository_name' in props: repository_name = props['repository_name'] else: - log.msg( - "Could not send status, " - "build has no repository_name property for Gitea.") - continue + match = re.match(self.ssh_url_match, sourcestamp['repository']) + if match is not None: + repository_name = match.group("repo_name") + else: + log.msg( + "Could not send status, " + "build has no repository_name property for Gitea.") + continue if 'owner' in props: repository_owner = props['owner'] else: - log.msg( - "Could not send status, " - "build has no owner property for Gitea.") - continue + match = re.match(self.ssh_url_match, sourcestamp['repository']) + if match is not None: + repository_owner = match.group("owner") + else: + log.msg( + "Could not send status, " + "build has no owner property for Gitea.") + continue try: sha = unicode2NativeString(sha) state = unicode2NativeString(state) diff --git a/buildbot_gitea/test/test_reporter.py b/buildbot_gitea/test/test_reporter.py index 8f6ce9b..0a6dae4 100644 --- a/buildbot_gitea/test/test_reporter.py +++ b/buildbot_gitea/test/test_reporter.py @@ -102,6 +102,20 @@ class TestGiteaStatusPush( build['complete'] = False 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 def test_noowner(self): self.setUpLogging()