File size: 1,121 Bytes
2a21e9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import base64          # For decoding Base64 content
import requests        # For HTTP GET on raw_url
from github import Github  # PyGithub

# ==== CHANGE VALUES BELOW ====================================
TOKEN     = "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"       # <-- Change: Your GitHub PAT
OWNER     = "Habil7"      # <-- Change: Repo owner
REPO_NAME = "git-demo"            # <-- Change: Repo name
PR_NUMBER = 4                       # <-- Change: Pull request number
# =============================================================

gh   = Github(TOKEN)
repo = gh.get_repo(f"{OWNER}/{REPO_NAME}")
pr   = repo.get_pull(PR_NUMBER)
print(pr)

# Print PR comments
print("\n--- PR Comments ---")
for comment in pr.get_issue_comments():
    print(f"{comment.user.login}: {comment.body}")

print(f"Number of files in PR: {pr.get_files().totalCount}")

for file in pr.get_files():
    print(f"\n=== {file.filename} ===")
    # Fetch and decode via PyGithub get_contents
    cf = repo.get_contents(file.filename, ref=pr.head.sha)
    content_via_api = base64.b64decode(cf.content).decode("utf-8")
    print(content_via_api)