diff --git a/github_rest_api/github.py b/github_rest_api/github.py index 808820e..5b1e78e 100644 --- a/github_rest_api/github.py +++ b/github_rest_api/github.py @@ -76,6 +76,17 @@ def put(self, url, raise_for_status: bool = True) -> requests.Response: resp.raise_for_status() return resp + def patch(self, url, raise_for_status: bool = True, **kwargs) -> requests.Response: + resp = requests.patch( + url=url, + headers=self._headers, + timeout=10, + **kwargs, + ) + if raise_for_status: + resp.raise_for_status() + return resp + class Repository(GitHub): """Abstraction of a GitHub repository.""" @@ -87,11 +98,14 @@ def __init__(self, token: str, repo: str): """ super().__init__(token) self._repo = repo - self._url_pull = f"https://api.github.com/repos/{repo}/pulls" - self._url_branches = f"https://api.github.com/repos/{repo}/branches" - self._url_refs = f"https://api.github.com/repos/{repo}/git/refs" - self._url_issues = f"https://api.github.com/repos/{repo}/issues" - self._url_releases = f"https://api.github.com/repos/{repo}/releases" + self._url = "https://api.github.com/repos" + self._url_repo = f"{self._url}/{repo}" + self._url_transfer = f"{self._url_repo}/transfer" + self._url_pull = f"{self._url_repo}/pulls" + self._url_branches = f"{self._url_repo}/branches" + self._url_refs = f"{self._url_repo}/git/refs" + self._url_issues = f"{self._url_repo}/issues" + self._url_releases = f"{self._url_repo}/releases" def get_releases(self) -> list[dict[str, Any]]: """List releases in this repository.""" @@ -272,6 +286,20 @@ def create_issue_comment(self, issue_number: int, body: str) -> dict[str, Any]: timeout=10, ).json() + def archive(self) -> requests.Response: + return self.patch( + url=self._url_repo, + json={"archived": True}, + ) + + def transfer(self, new_owner: str, new_name: str = "") -> requests.Response: + data = { + "new_owner": new_owner, + } + if new_name: + data["new_name"] = new_name + return self.post(url=self._url_transfer, json=data) + class RepositoryType(StrEnum): ALL = "all" diff --git a/pyproject.toml b/pyproject.toml index c6aad3b..95716ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "github_rest_api" -version = "0.29.0" +version = "0.30.0" description = "Simple wrapper of GitHub REST APIs." authors = [{ name = "Ben Du", email = "longendu@yahoo.com" }] requires-python = ">=3.11,<4" diff --git a/uv.lock b/uv.lock index 35ccba9..8dc7ec8 100644 --- a/uv.lock +++ b/uv.lock @@ -168,7 +168,7 @@ wheels = [ [[package]] name = "github-rest-api" -version = "0.28.0" +version = "0.30.0" source = { editable = "." } dependencies = [ { name = "dulwich" },