-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.py
More file actions
43 lines (33 loc) · 1.18 KB
/
github.py
File metadata and controls
43 lines (33 loc) · 1.18 KB
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
34
35
36
37
38
39
40
41
42
43
from github import Github
from typing import Tuple
def init_github_client(token: str) -> Github:
return Github(token)
def get_pr_diff(client: Github, repo_full_name: str, pr_number: int) -> Tuple[str, str]:
repo = client.get_repo(repo_full_name)
pr = repo.get_pull(pr_number)
title = pr.title
diff_text = ""
files = pr.get_files()
for file in files:
filename = file.filename
patch = file.patch or ""
diff_text += f"--- {filename} ---\n {patch}\n\n"
return title, diff_text
def post_review_comments(client, repo_full_name: str, pr_number: int, comments: list, summary: str):
# Use github api to post the inline comments and a summary review
repo = client.get_repo(repo_full_name)
pr = repo.get_pull(pr_number)
is_author = (pr.user.login == client.get_user().login)
event_type = "COMMENT" if is_author else "REQUEST_CHANGES"
pr.create_review(
body = summary,
event = event_type,
comments = [
{
"path": c["path"],
"position":None,
"line": c["line"],
"body": c["body"],
} for c in comments
]
)