Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions github_rest_api/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ def _extract_all(
params["page"] += 1


class IssueState(StrEnum):
Comment thread
dclong marked this conversation as resolved.
OPEN = "open"
CLOSED = "closed"
ALL = "all"


class Repository(GitHub):
"""Abstraction of a GitHub repository."""

Expand Down Expand Up @@ -282,6 +288,19 @@ def get_pull_requests(self, n: int = 0) -> list[dict[str, Any]]:
"""List pull requests in this repository."""
return self._extract_all(url=self._url_pull, n=n)

def get_issues(
self, state: IssueState = IssueState.OPEN, n: int = 0
) -> list[dict[str, Any]]:
Comment thread
dclong marked this conversation as resolved.
"""List issues in this repository.

:param state: Filter issues by state: ``open`` (the default),
``closed``, or ``all``. Note that GitHub's issues endpoint also
returns pull requests; each pull request carries a
``pull_request`` key.
:param n: The maximum number of issues to return (0 means all).
"""
return self._extract_all(url=self._url_issues, params={"state": state}, n=n)

def _generate_pull_request_content(
self, base: str, head: str, model: str
) -> tuple[str, str] | None:
Expand Down Expand Up @@ -499,6 +518,14 @@ def pr_has_rust_change(
"""
return self.pr_has_change(pr_number=pr_number, pred=pred)

def get_issue_comments(self, issue_number: int, n: int = 0) -> list[dict[str, Any]]:
"""List comments on an issue in this repository.

:param issue_number: The number of the issue.
:param n: The maximum number of comments to return (0 means all).
"""
return self._extract_all(url=f"{self._url_issues}/{issue_number}/comments", n=n)

def create_issue_comment(self, issue_number: int, body: str) -> dict[str, Any]:
"""Add a new comment to an issue.

Expand Down
19 changes: 19 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ def test_repository_get_branch():
assert branch["name"] == "main"


def test_get_issues_passes_url_and_state():
repo = Repository("token", "owner/name")
with patch.object(repo, "_extract_all", return_value=[]) as mock_extract:
repo.get_issues()
assert mock_extract.call_args.kwargs["url"] == (
"https://api.github.com/repos/owner/name/issues"
)
assert mock_extract.call_args.kwargs["params"] == {"state": "open"}


def test_get_issue_comments_passes_url():
repo = Repository("token", "owner/name")
with patch.object(repo, "_extract_all", return_value=[]) as mock_extract:
repo.get_issue_comments(7)
assert mock_extract.call_args.kwargs["url"] == (
"https://api.github.com/repos/owner/name/issues/7/comments"
)


def test_compare_url_encodes_branch_names():
repo = Repository("token", "owner/name")
response = MagicMock()
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading