bluenevus commited on
Commit
82690e2
·
verified ·
1 Parent(s): 43a582e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -104,36 +104,30 @@ 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
-
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"
136
- updated_summary = summary_content.replace("Releases\n", f"Releases\n{new_entry}")
 
 
 
 
 
 
 
137
 
138
  # Create a new branch for the PR
139
  base_branch = repo.default_branch
@@ -146,7 +140,7 @@ def update_summary_and_create_pr(repo_url, folder_location, new_file_name, markd
146
  summary_path,
147
  f"Update SUMMARY.md with new release notes {new_file_name}",
148
  updated_summary,
149
- repo.get_contents(summary_path).sha,
150
  branch=new_branch
151
  )
152
 
@@ -170,6 +164,7 @@ def update_summary_and_create_pr(repo_url, folder_location, new_file_name, markd
170
  pr_url = pr.html_url
171
  return f"Pull request created: {pr_url}"
172
  except Exception as e:
 
173
  return f"Error creating PR: {str(e)}"
174
 
175
  # App layout
 
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
  try:
112
  summary_file = repo.get_contents(summary_path)
113
  summary_content = summary_file.decoded_content.decode()
 
114
  except GithubException as e:
 
115
  if e.status == 404:
116
+ # If SUMMARY.md doesn't exist, create initial content
117
  summary_content = "# Summary\n\n## Releases\n"
 
 
 
 
 
 
118
  else:
119
+ raise
120
 
121
+ # Add new file link at the top of the Releases section
122
+ new_entry = f"* [{datetime.now().strftime('%b %d, %Y')}]({new_file_name})\n"
123
+ releases_index = summary_content.find("## Releases")
124
+ if releases_index != -1:
125
+ insert_position = summary_content.find("\n", releases_index) + 1
126
+ updated_summary = (summary_content[:insert_position] + new_entry +
127
+ summary_content[insert_position:])
128
+ else:
129
+ # If Releases section doesn't exist, add it
130
+ updated_summary = summary_content + f"\n## Releases\n{new_entry}"
131
 
132
  # Create a new branch for the PR
133
  base_branch = repo.default_branch
 
140
  summary_path,
141
  f"Update SUMMARY.md with new release notes {new_file_name}",
142
  updated_summary,
143
+ summary_file.sha if 'summary_file' in locals() else None,
144
  branch=new_branch
145
  )
146
 
 
164
  pr_url = pr.html_url
165
  return f"Pull request created: {pr_url}"
166
  except Exception as e:
167
+ print(f"Error: {str(e)}")
168
  return f"Error creating PR: {str(e)}"
169
 
170
  # App layout