-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_client.py
More file actions
25 lines (21 loc) · 911 Bytes
/
github_client.py
File metadata and controls
25 lines (21 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
class GitHubClient:
def __init__(self, token: str):
self.base = "https://api.github.com"
self.headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
def get_pr_diff(self, repo: str, pr_number: int) -> str:
url = f"{self.base}/repos/{repo}/pulls/{pr_number}"
headers = dict(self.headers)
headers["Accept"] = "application/vnd.github.v3.diff"
r = requests.get(url, headers=headers, timeout=30)
r.raise_for_status()
return r.text
def post_comment(self, repo: str, pr_number: int, body: str):
url = f"{self.base}/repos/{repo}/issues/{pr_number}/comments"
r = requests.post(url, headers=self.headers, json={"body": body}, timeout=30)
r.raise_for_status()
return r.json()