Skip to content
Merged
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
25 changes: 24 additions & 1 deletion src/lando/utils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get(self, path: str, *args, **kwargs) -> dict:

def post(self, path: str, *args, **kwargs) -> dict:
"""Send a POST request to the GitHub API with given args and kwargs."""
url = f"self.GITHUB_BASE_URL/{path}"
url = f"{self.GITHUB_BASE_URL}/{path}"
return self.session.post(url, *args, **kwargs)


Expand All @@ -88,6 +88,10 @@ def _get(self, path: str, *args, **kwargs) -> dict:
elif content_type == "application/vnd.github.diff; charset=utf-8":
return result.text

def _post(self, path: str, *args, **kwargs):
result = self.client.post(path, *args, **kwargs)
return result.json()

def list_pull_requests(self) -> list:
"""List all pull requests in the repo."""
return self._get(f"{self.repo_base_url}/pulls")
Expand All @@ -110,6 +114,25 @@ def get_patch(self, pull_number: int) -> str:
headers={"Accept": "application/vnd.github.patch"},
)

def open_pull_request(self, pull_number: int) -> dict:
"""Open the given pull request."""
return self._post(
f"{self.repo_base_url}/pulls/{pull_number}", json={"state": "open"}
)

def close_pull_request(self, pull_number: int) -> dict:
"""Close the given pull request."""
return self._post(
f"{self.repo_base_url}/pulls/{pull_number}", json={"state": "closed"}
)

def add_comment_to_pull_request(self, pull_number: int, comment: str) -> dict:
"""Add a comment to the given pull request."""
return self._post(
f"{self.repo_base_url}/issues/{pull_number}/comments",
json={"body": comment},
)
Comment thread
shtrom marked this conversation as resolved.


class PullRequest:
"""A class that parses data returned from the GitHub API for pull requests."""
Expand Down