bluenevus commited on
Commit
94a1176
·
verified ·
1 Parent(s): 82690e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -100,34 +100,38 @@ def generate_release_notes(git_provider, repo_url, start_date, end_date, folder_
100
  except Exception as e:
101
  return f"An error occurred: {str(e)}", None
102
 
103
- def update_summary_and_create_pr(repo_url, folder_location, new_file_name, markdown_content):
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
@@ -138,24 +142,24 @@ def update_summary_and_create_pr(repo_url, folder_location, new_file_name, markd
138
  # Update SUMMARY.md in the new branch
139
  repo.update_file(
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
 
147
  # Create the new release notes file
148
- new_file_path = f"{folder_location}/{new_file_name}"
149
  repo.create_file(
150
  new_file_path,
151
- f"Add release notes {new_file_name}",
152
  markdown_content,
153
  branch=new_branch
154
  )
155
 
156
  # Create a pull request
157
  pr = repo.create_pull(
158
- title=f"Add release notes {new_file_name} and update SUMMARY.md",
159
  body="Automatically generated PR to add new release notes and update SUMMARY.md.",
160
  head=new_branch,
161
  base=base_branch
 
100
  except Exception as e:
101
  return f"An error occurred: {str(e)}", None
102
 
103
+ def update_summary_and_create_pr(repo_url, folder_location, start_date, end_date, markdown_content):
104
  global pr_url
105
  try:
106
  g = Github(HF_GITHUB_TOKEN)
107
  repo = g.get_repo(repo_url)
108
 
109
+ # Generate file name based on end date
110
+ file_name = f"{end_date}.md"
111
+
112
+ # Determine SUMMARY.md location
113
+ summary_folder = '/'.join(folder_location.split('/')[:-1])
114
+ summary_path = f"{summary_folder}/SUMMARY.md"
115
+
116
  # Get the current content of SUMMARY.md
 
117
  try:
118
  summary_file = repo.get_contents(summary_path)
119
  summary_content = summary_file.decoded_content.decode()
120
  except GithubException as e:
121
  if e.status == 404:
122
+ summary_content = "# Summary\n\nReleases\n"
 
123
  else:
124
  raise
125
 
126
  # Add new file link at the top of the Releases section
127
+ new_entry = f"{end_date}\n"
128
+ releases_index = summary_content.find("Releases")
129
  if releases_index != -1:
130
  insert_position = summary_content.find("\n", releases_index) + 1
131
  updated_summary = (summary_content[:insert_position] + new_entry +
132
  summary_content[insert_position:])
133
  else:
134
+ updated_summary = summary_content + f"Releases\n{new_entry}"
 
135
 
136
  # Create a new branch for the PR
137
  base_branch = repo.default_branch
 
142
  # Update SUMMARY.md in the new branch
143
  repo.update_file(
144
  summary_path,
145
+ f"Update SUMMARY.md with new release notes {file_name}",
146
  updated_summary,
147
  summary_file.sha if 'summary_file' in locals() else None,
148
  branch=new_branch
149
  )
150
 
151
  # Create the new release notes file
152
+ new_file_path = f"{folder_location}/{file_name}"
153
  repo.create_file(
154
  new_file_path,
155
+ f"Add release notes {file_name}",
156
  markdown_content,
157
  branch=new_branch
158
  )
159
 
160
  # Create a pull request
161
  pr = repo.create_pull(
162
+ title=f"Add release notes {file_name} and update SUMMARY.md",
163
  body="Automatically generated PR to add new release notes and update SUMMARY.md.",
164
  head=new_branch,
165
  base=base_branch