- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_client.py
More file actions
Latest commit
33 lines (26 loc) · 931 Bytes
/
Copy pathgithub_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
fromurllib.parseimporturlparse
defparse_pr_url(pr_url:str)->tuple[str,str,int]:
path=urlparse(pr_url).path
parts=path.strip("/").split("/")
iflen(parts) !=4orparts[2] !="pull":
raiseValueError(f"Invalid PR URL:{pr_url}")
owner=parts[0]
repo=parts[1]
pr_number=parts[2]
returnowner,repo,pr_number
fromgithubimportGithub
defget_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= []
forfinpr.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
})
returnfiles