Revert extra re.sub and make original regex less greedy.

This commit is contained in:
Benjamin Füldner 2020-05-15 14:13:26 +02:00
parent c34b7389dc
commit 21e23ce4b8
1 changed files with 3 additions and 9 deletions

View File

@ -24,7 +24,7 @@ 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_\-\.]+)") 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,
@ -117,14 +117,10 @@ class GiteaStatusPush(http.HttpStatusPushBase):
if sha is None: if sha is None:
# No special revision for this, so ignore it # No special revision for this, so ignore it
continue continue
# Strip tailing .git to exclude it from re.match
ssh_url = re.sub('\.git$', '', sourcestamp['repository'])
if 'repository_name' in props: if 'repository_name' in props:
repository_name = props['repository_name'] repository_name = props['repository_name']
else: else:
match = re.match(self.ssh_url_match, ssh_url) match = re.match(self.ssh_url_match, sourcestamp['repository'])
if match is not None: if match is not None:
repository_name = match.group("repo_name") repository_name = match.group("repo_name")
else: else:
@ -132,11 +128,10 @@ class GiteaStatusPush(http.HttpStatusPushBase):
"Could not send status, " "Could not send status, "
"build has no repository_name property for Gitea.") "build has no repository_name property for Gitea.")
continue continue
if 'owner' in props: if 'owner' in props:
repository_owner = props['owner'] repository_owner = props['owner']
else: else:
match = re.match(self.ssh_url_match, ssh_url) match = re.match(self.ssh_url_match, sourcestamp['repository'])
if match is not None: if match is not None:
repository_owner = match.group("owner") repository_owner = match.group("owner")
else: else:
@ -144,7 +139,6 @@ class GiteaStatusPush(http.HttpStatusPushBase):
"Could not send status, " "Could not send status, "
"build has no owner property for Gitea.") "build has no owner property for Gitea.")
continue continue
try: try:
target_url = build['url'] target_url = build['url']
res = yield self.createStatus( res = yield self.createStatus(