Skip to content

Commit d6d57f0

Browse files
committed
fix(review): verify effective access for unlisted reviewers
Check effective write or admin access before rejecting an account omitted from the collaborator list. Keep public read access and lookup errors rejected, with regression tests and matching contributor guidance. Signed-off-by: Adrien Langou <alangou@nvidia.com>
1 parent 715a6f7 commit d6d57f0

3 files changed

Lines changed: 136 additions & 12 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Pull requests that touch the enforcement machinery or reviewer routing — anyth
7474

7575
Once your pull request represents [accepted work](#accepted-work), apply exactly one `area:` label and any relevant `topic:` labels. Follow [Labeling and Notifications](#labeling-and-notifications) before applying classification labels. The [reviewer routing workflow](.github/workflows/review-readiness.yml) requests all matching members of [REVIEWERS.md](REVIEWERS.md), excluding the author, when a PR opens ready for review, leaves draft status, or gains or loses an area/topic label. Reviewers do not need repository write access to receive requests or review PRs. Manual reviewer choices and people who have commented or reviewed are preserved. Propose roster membership changes through a reviewed PR.
7676

77-
Branch Checks rejects accounts in `REVIEWERS.md` that are not repository collaborators. Public read access alone does not qualify; read and triage collaborators are eligible.
77+
Branch Checks requires accounts in `REVIEWERS.md` to appear in the repository collaborator list or have confirmed write or admin permission. Public read access alone does not qualify; read and triage accounts must appear in the collaborator list.
7878

7979
If your pull request has been idle, ask for a reviewer in the pull request or in the CNCF Slack channel rather than waiting.
8080

‎tasks/scripts/check_reviewer_collaborators.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
"""Reject reviewer roster entries without repository collaborator membership."""
5+
"""Validate reviewer roster accounts against repository membership and permissions."""
66

77
import argparse
88
import subprocess
@@ -27,19 +27,31 @@ def main(argv: list[str] | None = None) -> int:
2727
pages=True,
2828
)
2929
}
30-
invalid = sorted(members - collaborators)
30+
invalid = []
31+
for login in sorted(members - collaborators):
32+
permission = _api(f"repos/{args.repo}/collaborators/{login}/permission")[
33+
"permission"
34+
]
35+
if permission in ("read", "none"):
36+
invalid.append(login)
37+
elif permission not in ("write", "admin"):
38+
raise ValueError(f"unexpected repository permission for {login}")
3139
if invalid:
32-
raise ValueError("non-collaborators in REVIEWERS.md: " + ", ".join(invalid))
40+
raise ValueError(
41+
"ineligible accounts in REVIEWERS.md: " + ", ".join(invalid)
42+
)
3343
except subprocess.CalledProcessError as exc:
3444
print(
35-
"Cannot list repository collaborators: " + (exc.stderr or str(exc)).strip(),
45+
"Cannot verify reviewer access: " + (exc.stderr or str(exc)).strip(),
3646
file=sys.stderr,
3747
)
3848
return 1
3949
except (OSError, ValueError, KeyError, TypeError) as exc:
4050
print(f"Reviewer roster: {exc}", file=sys.stderr)
4151
return 1
42-
print(f"All {len(members)} reviewer roster accounts are repository collaborators.")
52+
print(
53+
f"All {len(members)} reviewer roster accounts are eligible for review requests."
54+
)
4355
return 0
4456

4557

‎tasks/scripts/check_reviewer_collaborators_test.py‎

Lines changed: 118 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525

2626
class CollaboratorTests(unittest.TestCase):
27-
def run_check(self, response):
27+
def run_check(self, response, roster=ROSTER):
2828
with tempfile.TemporaryDirectory() as directory:
2929
path = Path(directory) / "REVIEWERS.md"
30-
path.write_text(ROSTER)
30+
path.write_text(roster)
3131
with (
3232
mock.patch.object(check.subprocess, "run", side_effect=response) as api,
3333
contextlib.redirect_stdout(io.StringIO()) as output,
@@ -40,25 +40,137 @@ def test_accepts_collaborators_on_all_pages_without_write_access(self):
4040
pages = [
4141
[{"login": "ALICE", "role_name": "read"}],
4242
[{"login": "bob", "role_name": "triage"}],
43+
[{"login": "outside", "role_name": "read"}],
4344
]
4445
result, api, _, _ = self.run_check(
45-
[subprocess.CompletedProcess([], 0, stdout=json.dumps(pages))]
46+
[subprocess.CompletedProcess([], 0, stdout=json.dumps(pages))],
47+
ROSTER + "| Outside | [@outside](https://github.com/outside) | Other |\n",
4648
)
4749
self.assertEqual(result, 0)
50+
self.assertEqual(api.call_count, 1)
4851
command = api.call_args.args[0]
4952
self.assertIn(
5053
"repos/owner/repo/collaborators?per_page=100&affiliation=all", command
5154
)
5255
self.assertIn("--paginate", command)
5356
self.assertIn("--slurp", command)
5457

55-
def test_reports_all_non_collaborators_in_sorted_order(self):
56-
result, _, _, errors = self.run_check(
57-
[subprocess.CompletedProcess([], 0, stdout="[[]]")]
58+
def test_reports_unlisted_read_and_none_in_sorted_order(self):
59+
result, api, output, errors = self.run_check(
60+
[
61+
subprocess.CompletedProcess([], 0, stdout="[[]]"),
62+
subprocess.CompletedProcess(
63+
[], 0, stdout='{"permission": "read", "role_name": "admin"}'
64+
),
65+
subprocess.CompletedProcess(
66+
[], 0, stdout='{"permission": "none", "role_name": "custom-role"}'
67+
),
68+
]
5869
)
5970
self.assertEqual(result, 1)
71+
self.assertEqual(output, "")
6072
self.assertIn("alice, bob", errors)
6173
self.assertIn("REVIEWERS.md", errors)
74+
self.assertEqual(api.call_count, 3)
75+
self.assertIn(
76+
"repos/owner/repo/collaborators/alice/permission",
77+
api.call_args_list[1].args[0],
78+
)
79+
self.assertIn(
80+
"repos/owner/repo/collaborators/bob/permission",
81+
api.call_args_list[2].args[0],
82+
)
83+
84+
def test_accepts_unlisted_writer_with_custom_role(self):
85+
result, api, output, errors = self.run_check(
86+
[
87+
subprocess.CompletedProcess([], 0, stdout='[[{"login": "bob"}]]'),
88+
subprocess.CompletedProcess(
89+
[], 0, stdout='{"permission": "write", "role_name": "custom-role"}'
90+
),
91+
]
92+
)
93+
self.assertEqual(result, 0, errors)
94+
self.assertIn("All 2 reviewer roster accounts", output)
95+
self.assertEqual(api.call_count, 2)
96+
command = api.call_args.args[0]
97+
self.assertEqual(
98+
command,
99+
[
100+
"gh",
101+
"api",
102+
"repos/owner/repo/collaborators/alice/permission",
103+
"--method",
104+
"GET",
105+
],
106+
)
107+
108+
def test_accepts_unlisted_administrator(self):
109+
result, _, output, errors = self.run_check(
110+
[
111+
subprocess.CompletedProcess([], 0, stdout='[[{"login": "bob"}]]'),
112+
subprocess.CompletedProcess(
113+
[], 0, stdout='{"permission": "admin", "role_name": "admin"}'
114+
),
115+
]
116+
)
117+
self.assertEqual(result, 0, errors)
118+
self.assertIn("All 2 reviewer roster accounts", output)
119+
120+
def test_permission_lookup_errors_fail_closed(self):
121+
for status in (403, 404, 500):
122+
with self.subTest(status=status):
123+
result, _, output, errors = self.run_check(
124+
[
125+
subprocess.CompletedProcess([], 0, stdout="[[]]"),
126+
subprocess.CalledProcessError(
127+
1, "gh", stderr=f"lookup failed (HTTP {status})"
128+
),
129+
]
130+
)
131+
self.assertEqual(result, 1)
132+
self.assertEqual(output, "")
133+
self.assertIn(f"HTTP {status}", errors)
134+
self.assertNotIn("ineligible accounts", errors)
135+
136+
def test_malformed_permission_responses_fail_closed(self):
137+
responses = ["invalid JSON", "", "null", "[]", "{}", '{"role_name": "admin"}']
138+
responses.extend(
139+
json.dumps({"permission": permission, "role_name": "admin"})
140+
for permission in (
141+
None,
142+
[],
143+
{},
144+
True,
145+
1,
146+
"maintain",
147+
"triage",
148+
"custom-role",
149+
)
150+
)
151+
for response in responses:
152+
with self.subTest(response=response):
153+
result, _, output, errors = self.run_check(
154+
[
155+
subprocess.CompletedProcess([], 0, stdout="[[]]"),
156+
subprocess.CompletedProcess([], 0, stdout=response),
157+
]
158+
)
159+
self.assertEqual(result, 1)
160+
self.assertEqual(output, "")
161+
self.assertIn("Reviewer roster:", errors)
162+
self.assertNotIn("ineligible accounts", errors)
163+
164+
def test_permission_process_error_fails_closed(self):
165+
result, _, output, errors = self.run_check(
166+
[
167+
subprocess.CompletedProcess([], 0, stdout="[[]]"),
168+
OSError("connection failed"),
169+
]
170+
)
171+
self.assertEqual(result, 1)
172+
self.assertEqual(output, "")
173+
self.assertIn("connection failed", errors)
62174

63175
def test_lookup_failure_fails_closed(self):
64176
result, _, output, errors = self.run_check(

0 commit comments

Comments
 (0)