BlueGit

ict rusty-teams

fix(ci): PR gate keeps one status label

- a failing gate removes "status: needs review" when it sets "status: needs info"
- tests for both label hand-overs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-25 · 6 days ago

Hash
a0f84959d7b2b1a22d0d111afdc4f8d7bb5f025f
Parent
ff2cccdd
2 files changed +35 −1
.github/scripts/pr_gate.py +2 −1
@@ -268,8 +268,9 @@ def remove_label(github: GitHub, number: int, labels: list[str], name: str) -> N
268 268
269 269
270 270 def update_labels(github: GitHub, number: int, labels: list[str], ready: bool) -> None:
271 """Sets only the gate's own labels; the maintainers' status labels stay as they are."""
271 """Sets only the gate's own labels (needs info, needs review); the maintainers' status labels stay as they are."""
272 272 if not ready:
273 remove_label(github, number, labels, LABEL_NEEDS_REVIEW)
273 274 add_label(github, number, labels, LABEL_NEEDS_INFO)
274 275 return
275 276 remove_label(github, number, labels, LABEL_NEEDS_INFO)
@@ -268,8 +268,9 @@ def remove_label(github: GitHub, number: int, labels: list[str], name: str) -> N
268
268
269
269
270def update_labels(github: GitHub, number: int, labels: list[str], ready: bool) -> None:
270def update_labels(github: GitHub, number: int, labels: list[str], ready: bool) -> None:
271 """Sets only the gate's own labels; the maintainers' status labels stay as they are."""
271 """Sets only the gate's own labels (needs info, needs review); the maintainers' status labels stay as they are."""
272 if not ready:
272 if not ready:
273 remove_label(github, number, labels, LABEL_NEEDS_REVIEW)
273 add_label(github, number, labels, LABEL_NEEDS_INFO)
274 add_label(github, number, labels, LABEL_NEEDS_INFO)
274 return
275 return
275 remove_label(github, number, labels, LABEL_NEEDS_INFO)
276 remove_label(github, number, labels, LABEL_NEEDS_INFO)
.github/scripts/test_pr_gate.py +33 −0
@@ -146,5 +146,38 @@ class DocumentationTests(unittest.TestCase):
146 146 self.assert_mentions("CONTRIBUTING.md", *self.shared_values())
147 147
148 148
149
150 class FakeGitHub:
151 def __init__(self):
152 self.calls = []
153
154 def request(self, method, path, payload=None):
155 self.calls.append((method, path, payload))
156
157
158 class LabelTests(unittest.TestCase):
159 def test_a_failing_gate_replaces_needs_review_with_needs_info(self):
160 github = FakeGitHub()
161 pr_gate.update_labels(github, 5, [pr_gate.LABEL_NEEDS_REVIEW], ready=False)
162 self.assertEqual(
163 github.calls,
164 [
165 ("DELETE", "/issues/5/labels/status%3A%20needs%20review", None),
166 ("POST", "/issues/5/labels", {"labels": [pr_gate.LABEL_NEEDS_INFO]}),
167 ],
168 )
169
170 def test_a_passing_gate_replaces_needs_info_with_needs_review(self):
171 github = FakeGitHub()
172 pr_gate.update_labels(github, 5, [pr_gate.LABEL_NEEDS_INFO], ready=True)
173 self.assertEqual(
174 github.calls,
175 [
176 ("DELETE", "/issues/5/labels/status%3A%20needs%20info", None),
177 ("POST", "/issues/5/labels", {"labels": [pr_gate.LABEL_NEEDS_REVIEW]}),
178 ],
179 )
180
181
149 182 if __name__ == "__main__":
150 183 unittest.main()
@@ -146,5 +146,38 @@ class DocumentationTests(unittest.TestCase):
146 self.assert_mentions("CONTRIBUTING.md", *self.shared_values())
146 self.assert_mentions("CONTRIBUTING.md", *self.shared_values())
147
147
148
148
149
150class FakeGitHub:
151 def __init__(self):
152 self.calls = []
153
154 def request(self, method, path, payload=None):
155 self.calls.append((method, path, payload))
156
157
158class LabelTests(unittest.TestCase):
159 def test_a_failing_gate_replaces_needs_review_with_needs_info(self):
160 github = FakeGitHub()
161 pr_gate.update_labels(github, 5, [pr_gate.LABEL_NEEDS_REVIEW], ready=False)
162 self.assertEqual(
163 github.calls,
164 [
165 ("DELETE", "/issues/5/labels/status%3A%20needs%20review", None),
166 ("POST", "/issues/5/labels", {"labels": [pr_gate.LABEL_NEEDS_INFO]}),
167 ],
168 )
169
170 def test_a_passing_gate_replaces_needs_info_with_needs_review(self):
171 github = FakeGitHub()
172 pr_gate.update_labels(github, 5, [pr_gate.LABEL_NEEDS_INFO], ready=True)
173 self.assertEqual(
174 github.calls,
175 [
176 ("DELETE", "/issues/5/labels/status%3A%20needs%20info", None),
177 ("POST", "/issues/5/labels", {"labels": [pr_gate.LABEL_NEEDS_REVIEW]}),
178 ],
179 )
180
181
149if __name__ == "__main__":
182if __name__ == "__main__":
150 unittest.main()
183 unittest.main()