Spaces:
Sleeping
Sleeping
Create pr_fetcher.py
Browse files- pr_fetcher.py +28 -0
pr_fetcher.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
def fetch_pr_diff(repo_owner, repo_name, pr_number, github_token):
|
| 4 |
+
"""
|
| 5 |
+
Fetches the diff of a pull request from a GitHub repository.
|
| 6 |
+
|
| 7 |
+
Args:
|
| 8 |
+
repo_owner (str): The owner of the GitHub repository.
|
| 9 |
+
repo_name (str): The name of the GitHub repository.
|
| 10 |
+
pr_number (int): The pull request number.
|
| 11 |
+
github_token (str): A personal access token for GitHub API.
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
str: The diff text of the pull request, or an error message.
|
| 15 |
+
"""
|
| 16 |
+
headers = {
|
| 17 |
+
"Accept": "application/vnd.github.v3.diff",
|
| 18 |
+
"Authorization": f"Bearer {github_token}"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/{pr_number}"
|
| 22 |
+
|
| 23 |
+
response = requests.get(url, headers=headers)
|
| 24 |
+
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
return response.text
|
| 27 |
+
else:
|
| 28 |
+
return f"Error {response.status_code}: {response.text}"
|