ci: a finished build reports on pull requests from forks (#2277)

When a Build APK run finishes, Build validation finds its pull request with
commits/{sha}/pulls, which GitHub answers with an empty list for a commit that
only exists on a fork. The validator then took the build as superseded, so the
"Build APK" status of every fork pull request stayed at "awaiting APK
compilation" after a successful build. It now falls back to the open pull
request for the run's head owner and branch, still requiring the head commit
to match.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-08 09:07:36 -05:00
1 parent c755d05473
commit 51e5e3a2a4
2 files changed
+15 -2

No files matched your search

+11 -2
View File
@@ -28,7 +28,7 @@ class ValidateApkTest(unittest.TestCase):
def git(self, *args):
return subprocess.check_output(["git", "-C", self.root, *args], text=True).strip()
def validate(self, message="Source change", body="", result="success", stale=False, completed=False, filename="source.kt", permission="write", role_name="write"):
def validate(self, message="Source change", body="", result="success", stale=False, completed=False, filename="source.kt", permission="write", role_name="write", fork=False):
(self.root / filename).parent.mkdir(parents=True, exist_ok=True)
(self.root / filename).write_text(message)
self.git("add", filename)
@@ -38,7 +38,8 @@ class ValidateApkTest(unittest.TestCase):
"title": "Source change", "body": body}
event = {"number": 1, "pull_request": {"head": {"sha": "stale" if stale else sha}}}
if completed:
event = {"workflow_run": {"event": "pull_request", "head_sha": "stale" if stale else sha}}
event = {"workflow_run": {"event": "pull_request", "head_sha": "stale" if stale else sha,
"head_branch": "fix/branch", "head_repository": {"owner": {"login": "contributor"}}}}
path = self.root / "event.json"
path.write_text(json.dumps(event))
@@ -51,6 +52,8 @@ class ValidateApkTest(unittest.TestCase):
if path.endswith("/pulls/1"):
return pr
if "/commits/" in path and path.endswith("/pulls"):
return [] if fork else [pr]
if path.endswith("/pulls?state=open&head=contributor%3Afix%2Fbranch"):
return [pr]
if "workflows/build.yml/runs?" in path:
return {"workflow_runs": [{"id": 7, "head_sha": sha, "status": "completed", "html_url": "https://example.org/build"}]}
@@ -94,6 +97,12 @@ class ValidateApkTest(unittest.TestCase):
def test_superseded_build_cannot_replace_current_status(self):
self.validate(stale=True, completed=True)
self.assertEqual(self.statuses, [])
self.validate(stale=True, completed=True, fork=True)
self.assertEqual(self.statuses, [])
def test_a_completed_fork_build_reports_on_its_pull_request(self):
self.validate(completed=True, fork=True)
self.assertEqual(self.statuses[-1]["state"], "success")
def test_documentation_passes_without_waiting_for_a_skipped_build(self):
self.validate(filename="README.md", result="pending")