diff --git a/tools/release/validate_apk.py b/tools/release/validate_apk.py index 3ff90c2e2..1e7e31f96 100644 --- a/tools/release/validate_apk.py +++ b/tools/release/validate_apk.py @@ -63,6 +63,10 @@ def main(): expected = run["head_sha"] if run["event"] == "pull_request": prs = api(f"repos/{repo}/commits/{expected}/pulls") + owner = (run.get("head_repository") or {}).get("owner", {}).get("login") + if not prs and owner and run.get("head_branch"): + query = urlencode({"state": "open", "head": f"{owner}:{run['head_branch']}"}) + prs = api(f"repos/{repo}/pulls?{query}") pr_number = next((pr["number"] for pr in prs if pr["state"] == "open" and pr["head"]["sha"] == expected), None) if pr_number is None: diff --git a/tools/tests/test_validate_apk.py b/tools/tests/test_validate_apk.py index 448d969a9..7bacefe74 100644 --- a/tools/tests/test_validate_apk.py +++ b/tools/tests/test_validate_apk.py @@ -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")