Skip to content

Commit 2f8ce1a

Browse files
committed
feat(github): add get_issues method to Repository
1 parent 1343d0a commit 2f8ce1a

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

github_rest_api/github.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ def get_pull_requests(self, n: int = 0) -> list[dict[str, Any]]:
282282
"""List pull requests in this repository."""
283283
return self._extract_all(url=self._url_pull, n=n)
284284

285+
def get_issues(self, state: str = "all", n: int = 0) -> list[dict[str, Any]]:
286+
"""List issues in this repository.
287+
288+
:param state: Filter issues by state: ``open``, ``closed``, or ``all``
289+
(the default). Note that GitHub's issues endpoint also returns pull
290+
requests; each pull request carries a ``pull_request`` key.
291+
:param n: The maximum number of issues to return (0 means all).
292+
"""
293+
return self._extract_all(url=self._url_issues, params={"state": state}, n=n)
294+
285295
def _generate_pull_request_content(
286296
self, base: str, head: str, model: str
287297
) -> tuple[str, str] | None:
@@ -499,6 +509,14 @@ def pr_has_rust_change(
499509
"""
500510
return self.pr_has_change(pr_number=pr_number, pred=pred)
501511

512+
def get_issue_comments(self, issue_number: int, n: int = 0) -> list[dict[str, Any]]:
513+
"""List comments on an issue in this repository.
514+
515+
:param issue_number: The number of the issue.
516+
:param n: The maximum number of comments to return (0 means all).
517+
"""
518+
return self._extract_all(url=f"{self._url_issues}/{issue_number}/comments", n=n)
519+
502520
def create_issue_comment(self, issue_number: int, body: str) -> dict[str, Any]:
503521
"""Add a new comment to an issue.
504522

tests/test_github.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ def test_repository_get_branch():
7676
assert branch["name"] == "main"
7777

7878

79+
def test_get_issues_passes_url_and_state():
80+
repo = Repository("token", "owner/name")
81+
with patch.object(repo, "_extract_all", return_value=[]) as mock_extract:
82+
repo.get_issues()
83+
assert mock_extract.call_args.kwargs["url"] == (
84+
"https://api.github.com/repos/owner/name/issues"
85+
)
86+
assert mock_extract.call_args.kwargs["params"] == {"state": "all"}
87+
88+
89+
def test_get_issue_comments_passes_url():
90+
repo = Repository("token", "owner/name")
91+
with patch.object(repo, "_extract_all", return_value=[]) as mock_extract:
92+
repo.get_issue_comments(7)
93+
assert mock_extract.call_args.kwargs["url"] == (
94+
"https://api.github.com/repos/owner/name/issues/7/comments"
95+
)
96+
97+
7998
def test_compare_url_encodes_branch_names():
8099
repo = Repository("token", "owner/name")
81100
response = MagicMock()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)