Skip to content

Commit b4d11a7

Browse files
committed
Status reporter now sends status to head repository if the current build is from a pull request.
1 parent b1dc019 commit b4d11a7

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

buildbot_gitea/reporter.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,15 @@ def _send_impl(self, reports):
158158

159159
for sourcestamp in sourcestamps:
160160
sha = sourcestamp['revision']
161+
repository_owner = None
161162
if sha is None:
162163
# No special revision for this, so ignore it
163164
continue
164-
if 'repository_name' in props:
165+
# If this is a pull request, send the status to the head repository
166+
if 'pr_id' in props:
167+
repository_name = props['head_reponame']
168+
repository_owner = props['head_owner']
169+
elif 'repository_name' in props:
165170
repository_name = props['repository_name']
166171
else:
167172
match = re.match(self.ssh_url_match, sourcestamp['repository'])
@@ -172,17 +177,18 @@ def _send_impl(self, reports):
172177
"Could not send status, "
173178
"build has no repository_name property for Gitea.")
174179
continue
175-
if 'owner' in props:
176-
repository_owner = props['owner']
177-
else:
178-
match = re.match(self.ssh_url_match, sourcestamp['repository'])
179-
if match is not None:
180-
repository_owner = match.group("owner")
180+
if repository_owner is None:
181+
if 'owner' in props:
182+
repository_owner = props['owner']
181183
else:
182-
log.msg(
183-
"Could not send status, "
184-
"build has no owner property for Gitea.")
185-
continue
184+
match = re.match(self.ssh_url_match, sourcestamp['repository'])
185+
if match is not None:
186+
repository_owner = match.group("owner")
187+
else:
188+
log.msg(
189+
"Could not send status, "
190+
"build has no owner property for Gitea.")
191+
continue
186192
try:
187193
target_url = build['url']
188194
res = yield self.createStatus(

buildbot_gitea/test/test_reporter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ def test_basic(self):
9494
build['results'] = FAILURE
9595
self.sp._got_event(('builds', 20, 'finished'), build)
9696

97+
@defer.inlineCallbacks
98+
def test_pullrequest(self):
99+
self.setupProps()
100+
self.reporter_test_props["pr_id"] = 42
101+
self.reporter_test_props["head_owner"] = 'foo'
102+
self.reporter_test_props["head_reponame"] = 'bar'
103+
build = yield self.setupBuildResults(SUCCESS)
104+
# we make sure proper calls to txrequests have been made
105+
self._http.expect(
106+
'post',
107+
'/api/v1/repos/foo/bar/statuses/d34db33fd43db33f',
108+
json={'state': 'success',
109+
'target_url': 'http://localhost:8080/#builders/79/builds/0',
110+
'description': 'Build done.', 'context': 'buildbot/pull_request/Builder0'})
111+
112+
build['complete'] = True
113+
self.sp._got_event(('builds', 20, 'finished'), build)
114+
97115
@defer.inlineCallbacks
98116
def test_sshurl(self):
99117
self.setupProps()

buildbot_gitea/webhook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def process_pull_request(self, payload, event_type, codebase):
111111
'head_repo_id': head['repo_id'],
112112
'head_repository': head['repo']['clone_url'],
113113
'head_git_ssh_url': head['repo']['ssh_url'],
114+
'head_owner': head['repo']['owner']['username'],
115+
'head_reponame': head['repo']['name'],
114116
'pr_id': pull_request['id'],
115117
'pr_number': pull_request['number'],
116118
'repository_name': repository['name'],

0 commit comments

Comments
 (0)