Status reporter now sends status to head repository if the current build is from a pull request.
This commit is contained in:
parent
b1dc019e60
commit
b4d11a7058
|
@ -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,17 +177,18 @@ 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 'owner' in props:
|
if repository_owner is None:
|
||||||
repository_owner = props['owner']
|
if 'owner' in props:
|
||||||
else:
|
repository_owner = props['owner']
|
||||||
match = re.match(self.ssh_url_match, sourcestamp['repository'])
|
|
||||||
if match is not None:
|
|
||||||
repository_owner = match.group("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:
|
||||||
target_url = build['url']
|
target_url = build['url']
|
||||||
res = yield self.createStatus(
|
res = yield self.createStatus(
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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'],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user