Spaces:
Running
Running
File size: 1,262 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import os
import json
import base64
import requests
from github import Github
# Path to the GitHub Actions event payload
event_path = os.environ.get("GITHUB_EVENT_PATH")
if not event_path or not os.path.exists(event_path):
print("No event payload found.")
exit(1)
with open(event_path, "r") as f:
event = json.load(f)
# Only proceed if this is a PR comment event
if "pull_request" not in event.get("issue", {}):
print("Not a PR comment event.")
exit(0)
pr_number = event["issue"]["number"]
comment_body = event["comment"]["body"]
repo_full_name = event["repository"]["full_name"]
token = os.environ.get("GITHUB_TOKEN")
if not token:
print("No GITHUB_TOKEN found in environment.")
exit(1)
gh = Github(token)
repo = gh.get_repo(repo_full_name)
pr = repo.get_pull(pr_number)
files = []
for file in pr.get_files():
cf = repo.get_contents(file.filename, ref=pr.head.sha)
content = base64.b64decode(cf.content).decode("utf-8")
files.append({"filename": file.filename, "content": content})
fastapi_url = "http://127.0.0.1:8000/pr-comments"
payload = {
"comment": comment_body,
"files": files
}
response = requests.post(fastapi_url, json=payload)
print(f"FastAPI response: {response.status_code} {response.text}")
|