Skip to content

Commit 73d24c2

Browse files
committed
Skip draft PRs in review scan
- Drop draft PRs in list_open_prs_by_authors before building OpenPR - Add draft property to the _PullRequest protocol - Add draft field to _FakePull and cover the skip with a new test Draft PRs are still in progress and not ready for the reviewer workflow, so the trusted-author scan filters them out alongside its existing author check, avoiding dispatch and fingerprinting on PRs the author hasn't marked ready for review. Signed-off-by: Jean Schmidt <contato@jschmidt.me>
1 parent f507fef commit 73d24c2

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

greenlight/src/greenlight/github_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def head(self) -> _PRBase: ...
4444
def updated_at(self) -> datetime | None: ...
4545
@property
4646
def labels(self) -> Iterable[_Label]: ...
47+
@property
48+
def draft(self) -> bool: ...
4749

4850
class _Repo(Protocol):
4951
def get_pulls(self, state: str) -> Iterable[_PullRequest]: ...
@@ -172,6 +174,8 @@ def list_open_prs_by_authors(client: _RepoClient, repo: str, authors: Iterable[s
172174
continue
173175
login = user.login
174176
if login and login.lower() in trusted:
177+
if pr.draft:
178+
continue
175179
updated_at = pr.updated_at
176180
prs.append(
177181
OpenPR(

greenlight/tests/test_github_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
head_sha: str = "head-sha",
3131
updated_at: datetime | None = None,
3232
labels: list[str] | None = None,
33+
draft: bool = False,
3334
) -> None:
3435
self.number = number
3536
self.user = _FakeUser(login) if login is not None else None
@@ -38,6 +39,7 @@ def __init__(
3839
self.head = _FakeBase(head_sha)
3940
self.updated_at = updated_at
4041
self.labels = [_FakeLabel(name) for name in (labels or [])]
42+
self.draft = draft
4143

4244

4345
class _FakeRepo:
@@ -263,6 +265,20 @@ def test_list_open_prs_by_authors_skips_pulls_with_no_user():
263265
assert [pr.author for pr in prs] == ["alice"]
264266

265267

268+
def test_list_open_prs_by_authors_skips_draft_pulls():
269+
client = _client_with_pulls(
270+
[
271+
_FakePull(1, "alice", "draft in progress", "https://example.test/1", draft=True),
272+
_FakePull(2, "alice", "ready for review", "https://example.test/2", draft=False),
273+
]
274+
)
275+
276+
prs = github_client.list_open_prs_by_authors(client, "pytorch/pytorch", ["alice"])
277+
278+
assert [pr.number for pr in prs] == [2]
279+
assert [pr.author for pr in prs] == ["alice"]
280+
281+
266282
def test_list_open_prs_by_authors_sorts_output_by_pr_number():
267283
client = _client_with_pulls(
268284
[

0 commit comments

Comments
 (0)