kumar1907/Code_Review_Agent
0
1import requests2 3def fetch_pr_diff(owner, repo, pr_number, token=None):4 headers = {5 "Accept": "application/vnd.github.v3.diff"6 }7 if token:8 headers["Authorization"] = f"token {token}"9 10 url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"11 response = requests.get(url, headers=headers)12 13 if response.status_code == 200:14 return response.text15 elif response.status_code == 404:16 return "Error: PR not found. Check the repo and PR number."17 elif response.status_code == 401:18 return "Error: Unauthorized. Check your GitHub token."19 else:20 return f"Error: Could not fetch PR. Status code: {response.status_code}"21 