bluenevus commited on
Commit
b626f41
·
verified ·
1 Parent(s): 3f7b2a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -119,19 +119,19 @@ def update_summary_and_create_pr(repo_url, folder_location, start_date, end_date
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
@@ -170,7 +170,7 @@ def update_summary_and_create_pr(repo_url, folder_location, start_date, end_date
170
  except Exception as e:
171
  print(f"Error: {str(e)}")
172
  return f"Error creating PR: {str(e)}"
173
-
174
  # App layout
175
  app.layout = dbc.Container([
176
  html.H1("Automated Release Notes Generator", className="mb-4"),
@@ -215,6 +215,10 @@ app.layout = dbc.Container([
215
  dbc.Button("Generate Release Notes", id="generate-button", color="primary", className="mr-2"),
216
  dbc.Button("Download Markdown", id="download-button", color="secondary", className="mr-2", disabled=True),
217
  dbc.Button("Create PR", id="pr-button", color="info", disabled=True)
 
 
 
 
218
  ], width=12, className="mb-3"),
219
  ]),
220
  ]),
@@ -238,7 +242,8 @@ app.layout = dbc.Container([
238
  Output("download-button", "disabled"),
239
  Output("pr-button", "disabled"),
240
  Output("download-markdown", "data"),
241
- Output("pr-button", "children")],
 
242
  [Input("generate-button", "n_clicks"),
243
  Input("download-button", "n_clicks"),
244
  Input("pr-button", "n_clicks")],
@@ -254,35 +259,35 @@ def handle_all_actions(generate_clicks, download_clicks, pr_clicks,
254
  ctx = dash.callback_context
255
 
256
  if not ctx.triggered:
257
- return "", True, True, None, "Create PR"
258
 
259
  button_id = ctx.triggered[0]['prop_id'].split('.')[0]
260
 
261
  if button_id == "generate-button":
262
  notes, file_name = generate_release_notes(git_provider, repo_url, start_date, end_date, folder_location)
263
- return notes, False, False, None, "Create PR"
264
 
265
  elif button_id == "download-button":
266
  if generated_file is None:
267
- return dash.no_update, dash.no_update, dash.no_update, None, dash.no_update
268
  return (dash.no_update, dash.no_update, dash.no_update,
269
  dcc.send_bytes(generated_file.getvalue(), f"release_notes_{datetime.now().strftime('%Y%m%d%H%M%S')}.md"),
270
- dash.no_update)
271
 
272
  elif button_id == "pr-button":
273
  if generated_file is None:
274
- return dash.no_update, dash.no_update, dash.no_update, None, "Error: No file generated"
275
 
276
  markdown_content = generated_file.getvalue().decode()
277
 
278
  result = update_summary_and_create_pr(repo_url, folder_location, start_date, end_date, markdown_content)
279
 
280
  if pr_url:
281
- return dash.no_update, dash.no_update, True, None, f"PR Created: {pr_url}"
282
  else:
283
- return dash.no_update, dash.no_update, False, None, result
284
 
285
- return dash.no_update, dash.no_update, dash.no_update, None, dash.no_update
286
 
287
  if __name__ == '__main__':
288
  print("Starting the Dash application...")
 
119
  summary_content = summary_file.decoded_content.decode()
120
  except GithubException as e:
121
  if e.status == 404:
122
+ summary_content = "* [Releases](README.md)\n"
123
  else:
124
  raise
125
 
126
  # Add new file link at the top of the Releases section
127
+ new_entry = f"* [{end_date}](rel/{file_name})\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](README.md)\n{new_entry}"
135
 
136
  # Create a new branch for the PR
137
  base_branch = repo.default_branch
 
170
  except Exception as e:
171
  print(f"Error: {str(e)}")
172
  return f"Error creating PR: {str(e)}"
173
+
174
  # App layout
175
  app.layout = dbc.Container([
176
  html.H1("Automated Release Notes Generator", className="mb-4"),
 
215
  dbc.Button("Generate Release Notes", id="generate-button", color="primary", className="mr-2"),
216
  dbc.Button("Download Markdown", id="download-button", color="secondary", className="mr-2", disabled=True),
217
  dbc.Button("Create PR", id="pr-button", color="info", disabled=True)
218
+ dcc.Loading(
219
+ id="pr-loading",
220
+ type="circle",
221
+ children=[html.Div(id="pr-output")
222
  ], width=12, className="mb-3"),
223
  ]),
224
  ]),
 
242
  Output("download-button", "disabled"),
243
  Output("pr-button", "disabled"),
244
  Output("download-markdown", "data"),
245
+ Output("pr-button", "children"),
246
+ Output("pr-output", "children")],
247
  [Input("generate-button", "n_clicks"),
248
  Input("download-button", "n_clicks"),
249
  Input("pr-button", "n_clicks")],
 
259
  ctx = dash.callback_context
260
 
261
  if not ctx.triggered:
262
+ return "", True, True, None, "Create PR", ""
263
 
264
  button_id = ctx.triggered[0]['prop_id'].split('.')[0]
265
 
266
  if button_id == "generate-button":
267
  notes, file_name = generate_release_notes(git_provider, repo_url, start_date, end_date, folder_location)
268
+ return notes, False, False, None, "Create PR", ""
269
 
270
  elif button_id == "download-button":
271
  if generated_file is None:
272
+ return dash.no_update, dash.no_update, dash.no_update, None, dash.no_update, ""
273
  return (dash.no_update, dash.no_update, dash.no_update,
274
  dcc.send_bytes(generated_file.getvalue(), f"release_notes_{datetime.now().strftime('%Y%m%d%H%M%S')}.md"),
275
+ dash.no_update, "")
276
 
277
  elif button_id == "pr-button":
278
  if generated_file is None:
279
+ return dash.no_update, dash.no_update, dash.no_update, None, "Error: No file generated", "No file generated"
280
 
281
  markdown_content = generated_file.getvalue().decode()
282
 
283
  result = update_summary_and_create_pr(repo_url, folder_location, start_date, end_date, markdown_content)
284
 
285
  if pr_url:
286
+ return dash.no_update, dash.no_update, True, None, f"PR Created", f"PR Created: {pr_url}"
287
  else:
288
+ return dash.no_update, dash.no_update, False, None, "PR Creation Failed", result
289
 
290
+ return dash.no_update, dash.no_update, dash.no_update, None, dash.no_update, ""
291
 
292
  if __name__ == '__main__':
293
  print("Starting the Dash application...")