Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ def generate_release_notes(github_repo, github_token, gemini_api_key, start_date
|
|
19 |
commit_text = "\n".join(commit_messages)
|
20 |
|
21 |
if not commit_text:
|
22 |
-
return "No commits found in the specified date range.", None
|
23 |
|
24 |
genai.configure(api_key=gemini_api_key)
|
25 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
@@ -37,12 +37,11 @@ def generate_release_notes(github_repo, github_token, gemini_api_key, start_date
|
|
37 |
Provide a concise summary for each item. Do not include any links, but keep issue numbers if present.
|
38 |
|
39 |
Important formatting instructions:
|
40 |
-
-
|
41 |
-
- Use
|
42 |
-
-
|
43 |
-
-
|
44 |
-
-
|
45 |
-
- be sure to briefly explain the why and benefits of the change for average user that are non technical
|
46 |
"""
|
47 |
|
48 |
response = model.generate_content(prompt)
|
@@ -54,30 +53,35 @@ def generate_release_notes(github_repo, github_token, gemini_api_key, start_date
|
|
54 |
current_list_style = None
|
55 |
for line in release_notes.split('\n'):
|
56 |
line = line.strip()
|
57 |
-
if line.
|
58 |
-
doc.add_heading(line, level=1)
|
59 |
current_list_style = None
|
60 |
-
elif line:
|
|
|
|
|
|
|
61 |
if current_list_style is None:
|
62 |
current_list_style = doc.add_paragraph().style
|
63 |
current_list_style.name = 'List Bullet'
|
64 |
current_list_style.font.size = docx.shared.Pt(11)
|
65 |
-
doc.add_paragraph(line, style=current_list_style)
|
|
|
|
|
66 |
|
67 |
temp_file = "release_notes.docx"
|
68 |
doc.save(temp_file)
|
69 |
|
70 |
-
return release_notes, temp_file
|
71 |
|
72 |
except GithubException as e:
|
73 |
if e.status == 401:
|
74 |
-
return "Error: Invalid GitHub token or insufficient permissions.", None
|
75 |
elif e.status == 404:
|
76 |
-
return f"Error: Repository not found. Please check the GitHub repository name. Attempted to access: {github_repo}", None
|
77 |
else:
|
78 |
-
return f"GitHub API error: {str(e)}", None
|
79 |
except Exception as e:
|
80 |
-
return f"An error occurred: {str(e)}", None
|
81 |
|
82 |
default_end_date = datetime.now()
|
83 |
default_start_date = default_end_date - timedelta(days=30)
|
@@ -101,7 +105,8 @@ iface = gr.Interface(
|
|
101 |
],
|
102 |
outputs=[
|
103 |
gr.Textbox(label="Generated Release Notes"),
|
104 |
-
gr.File(label="Download Release Notes")
|
|
|
105 |
],
|
106 |
title="Automated Release Notes Generator",
|
107 |
description="Generate release notes based on GitHub commits using Gemini AI. Enter start and end dates (YYYY-MM-DD) to define the time range for commits.",
|
|
|
19 |
commit_text = "\n".join(commit_messages)
|
20 |
|
21 |
if not commit_text:
|
22 |
+
return "No commits found in the specified date range.", None, None
|
23 |
|
24 |
genai.configure(api_key=gemini_api_key)
|
25 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
|
|
37 |
Provide a concise summary for each item. Do not include any links, but keep issue numbers if present.
|
38 |
|
39 |
Important formatting instructions:
|
40 |
+
- Use proper Markdown syntax
|
41 |
+
- Use # for main headers and ## for subheaders
|
42 |
+
- Use - for list items
|
43 |
+
- Keep the text structure simple and easy to read
|
44 |
+
- Be sure to briefly explain the why and benefits of the change for average users that are non-technical
|
|
|
45 |
"""
|
46 |
|
47 |
response = model.generate_content(prompt)
|
|
|
53 |
current_list_style = None
|
54 |
for line in release_notes.split('\n'):
|
55 |
line = line.strip()
|
56 |
+
if line.startswith('# '):
|
57 |
+
doc.add_heading(line[2:], level=1)
|
58 |
current_list_style = None
|
59 |
+
elif line.startswith('## '):
|
60 |
+
doc.add_heading(line[3:], level=2)
|
61 |
+
current_list_style = None
|
62 |
+
elif line.startswith('- '):
|
63 |
if current_list_style is None:
|
64 |
current_list_style = doc.add_paragraph().style
|
65 |
current_list_style.name = 'List Bullet'
|
66 |
current_list_style.font.size = docx.shared.Pt(11)
|
67 |
+
doc.add_paragraph(line[2:], style=current_list_style)
|
68 |
+
elif line:
|
69 |
+
doc.add_paragraph(line)
|
70 |
|
71 |
temp_file = "release_notes.docx"
|
72 |
doc.save(temp_file)
|
73 |
|
74 |
+
return release_notes, temp_file, release_notes
|
75 |
|
76 |
except GithubException as e:
|
77 |
if e.status == 401:
|
78 |
+
return "Error: Invalid GitHub token or insufficient permissions.", None, None
|
79 |
elif e.status == 404:
|
80 |
+
return f"Error: Repository not found. Please check the GitHub repository name. Attempted to access: {github_repo}", None, None
|
81 |
else:
|
82 |
+
return f"GitHub API error: {str(e)}", None, None
|
83 |
except Exception as e:
|
84 |
+
return f"An error occurred: {str(e)}", None, None
|
85 |
|
86 |
default_end_date = datetime.now()
|
87 |
default_start_date = default_end_date - timedelta(days=30)
|
|
|
105 |
],
|
106 |
outputs=[
|
107 |
gr.Textbox(label="Generated Release Notes"),
|
108 |
+
gr.File(label="Download Release Notes (DOCX)"),
|
109 |
+
gr.File(label="Download Release Notes (Markdown)", file_types=[".md"])
|
110 |
],
|
111 |
title="Automated Release Notes Generator",
|
112 |
description="Generate release notes based on GitHub commits using Gemini AI. Enter start and end dates (YYYY-MM-DD) to define the time range for commits.",
|