Status reporter now sends status to head repository if the current build is from a pull request.

This commit is contained in:
Marvin Pohl 2021-05-16 01:37:03 +02:00
parent b1dc019e60
commit b4d11a7058
3 changed files with 37 additions and 11 deletions

View File

@ -158,10 +158,15 @@ class GiteaStatusPush(http.ReporterBase):
for sourcestamp in sourcestamps: for sourcestamp in sourcestamps:
sha = sourcestamp['revision'] sha = sourcestamp['revision']
repository_owner = None
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
if 'repository_name' in props: # If this is a pull request, send the status to the head repository
if 'pr_id' in props:
repository_name = props['head_reponame']
repository_owner = props['head_owner']
elif 'repository_name' in props:
repository_name = props['repository_name'] repository_name = props['repository_name']
else: else:
match = re.match(self.ssh_url_match, sourcestamp['repository']) match = re.match(self.ssh_url_match, sourcestamp['repository'])
@ -172,6 +177,7 @@ class GiteaStatusPush(http.ReporterBase):
"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 repository_owner is None:
if 'owner' in props: if 'owner' in props:
repository_owner = props['owner'] repository_owner = props['owner']
else: else:

View File

@ -94,6 +94,24 @@ class TestGiteaStatusPush(
build['results'] = FAILURE build['results'] = FAILURE
self.sp._got_event(('builds', 20, 'finished'), build) self.sp._got_event(('builds', 20, 'finished'), build)
@defer.inlineCallbacks
def test_pullrequest(self):
self.setupProps()
self.reporter_test_props["pr_id"] = 42
self.reporter_test_props["head_owner"] = 'foo'
self.reporter_test_props["head_reponame"] = 'bar'
build = yield self.setupBuildResults(SUCCESS)
# we make sure proper calls to txrequests have been made
self._http.expect(
'post',
'/api/v1/repos/foo/bar/statuses/d34db33fd43db33f',
json={'state': 'success',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build done.', 'context': 'buildbot/pull_request/Builder0'})
build['complete'] = True
self.sp._got_event(('builds', 20, 'finished'), build)
@defer.inlineCallbacks @defer.inlineCallbacks
def test_sshurl(self): def test_sshurl(self):
self.setupProps() self.setupProps()

View File

@ -111,6 +111,8 @@ class GiteaHandler(BaseHookHandler):
'head_repo_id': head['repo_id'], 'head_repo_id': head['repo_id'],
'head_repository': head['repo']['clone_url'], 'head_repository': head['repo']['clone_url'],
'head_git_ssh_url': head['repo']['ssh_url'], 'head_git_ssh_url': head['repo']['ssh_url'],
'head_owner': head['repo']['owner']['username'],
'head_reponame': head['repo']['name'],
'pr_id': pull_request['id'], 'pr_id': pull_request['id'],
'pr_number': pull_request['number'], 'pr_number': pull_request['number'],
'repository_name': repository['name'], 'repository_name': repository['name'],