Spaces:
Sleeping
Sleeping
| import requests | |
| def fetch_pr_diff(owner, repo, pr_number, token=None): | |
| headers = { | |
| "Accept": "application/vnd.github.v3.diff" | |
| } | |
| if token: | |
| headers["Authorization"] = f"token {token}" | |
| url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}" | |
| response = requests.get(url, headers=headers) | |
| if response.status_code == 200: | |
| return response.text | |
| elif response.status_code == 404: | |
| return "Error: PR not found. Check the repo and PR number." | |
| elif response.status_code == 401: | |
| return "Error: Unauthorized. Check your GitHub token." | |
| else: | |
| return f"Error: Could not fetch PR. Status code: {response.status_code}" | |