Update app.py
Browse files
app.py
CHANGED
|
@@ -104,11 +104,32 @@ def update_summary_and_create_pr(repo_url, folder_location, new_file_name, markd
|
|
| 104 |
global pr_url
|
| 105 |
try:
|
| 106 |
g = Github(HF_GITHUB_TOKEN)
|
|
|
|
|
|
|
| 107 |
repo = g.get_repo(repo_url)
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
| 109 |
# Get the current content of SUMMARY.md
|
| 110 |
summary_path = f"{folder_location}/SUMMARY.md"
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# Add new file to the top of the Releases section
|
| 114 |
new_entry = f"{datetime.now().strftime('%b %d, %Y')}\n"
|
|
|
|
| 104 |
global pr_url
|
| 105 |
try:
|
| 106 |
g = Github(HF_GITHUB_TOKEN)
|
| 107 |
+
|
| 108 |
+
# Use the repo_url parameter instead of hard-coding
|
| 109 |
repo = g.get_repo(repo_url)
|
| 110 |
+
|
| 111 |
+
print(f"Accessing repo: {repo.full_name}")
|
| 112 |
+
print(f"Folder location: {folder_location}")
|
| 113 |
+
|
| 114 |
# Get the current content of SUMMARY.md
|
| 115 |
summary_path = f"{folder_location}/SUMMARY.md"
|
| 116 |
+
try:
|
| 117 |
+
summary_file = repo.get_contents(summary_path)
|
| 118 |
+
summary_content = summary_file.decoded_content.decode()
|
| 119 |
+
print(f"Successfully retrieved SUMMARY.md from {summary_path}")
|
| 120 |
+
except GithubException as e:
|
| 121 |
+
print(f"Error accessing {summary_path}: {e}")
|
| 122 |
+
if e.status == 404:
|
| 123 |
+
print("SUMMARY.md not found. Attempting to create it.")
|
| 124 |
+
summary_content = "# Summary\n\n## Releases\n"
|
| 125 |
+
try:
|
| 126 |
+
repo.create_file(summary_path, "Create SUMMARY.md", summary_content, branch="main")
|
| 127 |
+
print(f"Created SUMMARY.md at {summary_path}")
|
| 128 |
+
except Exception as create_error:
|
| 129 |
+
print(f"Error creating SUMMARY.md: {create_error}")
|
| 130 |
+
return f"Error creating SUMMARY.md: {str(create_error)}"
|
| 131 |
+
else:
|
| 132 |
+
return f"Error accessing repository content: {str(e)}"
|
| 133 |
|
| 134 |
# Add new file to the top of the Releases section
|
| 135 |
new_entry = f"{datetime.now().strftime('%b %d, %Y')}\n"
|