codereviewer / test.py
shekkari21's picture
Deploy to HF Space
2a21e9f
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)