-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_client.py
More file actions
33 lines (26 loc) · 931 Bytes
/
github_client.py
File metadata and controls
33 lines (26 loc) · 931 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
26
27
28
29
30
31
32
33
from urllib.parse import urlparse
def parse_pr_url(pr_url:str)->tuple[str,str,int]:
path = urlparse(pr_url).path
parts = path.strip("/").split("/")
if len(parts) != 4 or parts[2] != "pull":
raise ValueError(f"Invalid PR URL:{pr_url}")
owner = parts[0]
repo = parts[1]
pr_number = parts[2]
return owner,repo,pr_number
from github import Github
def get_pr_files(pr_url: str, token: str) -> list[dict]:
owner, repo, pr_number = parse_pr_url(pr_url)
g = Github(token)
repo = g.get_repo(f"{owner}/{repo}")
pr = repo.get_pull(pr_number)
files = []
for f in pr.get_files():
files.append({
"filename": f.filename,
"status": f.status, # added, modified, removed
"additions": f.additions,
"deletions": f.deletions,
"patch": f.patch # the actual diff
})
return files