bluenevus commited on
Commit
1334bbf
·
verified ·
1 Parent(s): ae5b54e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -37
app.py CHANGED
@@ -3,39 +3,6 @@ from datetime import datetime, timedelta
3
  import google.generativeai as genai
4
  from github import Github, GithubException
5
  import docx
6
- import re
7
-
8
- def remove_links_keep_issue_numbers(text):
9
- return re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', text)
10
-
11
- def strip_markdown(text):
12
- # Remove headers
13
- text = re.sub(r'^#+\s*', '', text, flags=re.MULTILINE)
14
- # Remove bold/italic without removing adjacent characters
15
- text = re.sub(r'(\*{1,2})([^\*]+)\1', r'\2', text)
16
- # Remove inline code without removing adjacent characters
17
- text = re.sub(r'`([^`]+)`', r'\1', text)
18
- # Remove blockquotes
19
- text = re.sub(r'^\s*>\s*', '', text, flags=re.MULTILINE)
20
- return text.strip()
21
-
22
- def markdown_to_docx(doc, markdown_text):
23
- lines = markdown_text.split('\n')
24
-
25
- for line in lines:
26
- stripped_line = strip_markdown(line)
27
- if line.lstrip().startswith('# '):
28
- doc.add_heading(stripped_line, level=1)
29
- elif line.lstrip().startswith('## '):
30
- doc.add_heading(stripped_line, level=2)
31
- elif line.lstrip().startswith('### '):
32
- doc.add_heading(stripped_line, level=3)
33
- elif line.strip().startswith('- ') or line.strip().startswith('* '):
34
- doc.add_paragraph(stripped_line.strip()[2:], style='List Bullet')
35
- elif re.match(r'^\d+\.', line.strip()):
36
- doc.add_paragraph(stripped_line.strip(), style='List Number')
37
- else:
38
- doc.add_paragraph(stripped_line)
39
 
40
  def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
41
  try:
@@ -65,16 +32,29 @@ def generate_release_notes(github_url, github_token, gemini_api_key, start_date,
65
  3. Improvements
66
  4. Breaking Changes (if any)
67
 
68
- Provide a concise summary for each item. Do not include any links, but keep issue numbers if present."""
 
 
 
 
 
 
 
 
69
 
70
  response = model.generate_content(prompt)
71
-
72
- release_notes = remove_links_keep_issue_numbers(response.text)
73
 
74
  doc = docx.Document()
75
  doc.add_heading('Release Notes', 0)
76
 
77
- markdown_to_docx(doc, release_notes)
 
 
 
 
 
 
78
 
79
  temp_file = "release_notes.docx"
80
  doc.save(temp_file)
 
3
  import google.generativeai as genai
4
  from github import Github, GithubException
5
  import docx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
8
  try:
 
32
  3. Improvements
33
  4. Breaking Changes (if any)
34
 
35
+ Provide a concise summary for each item. Do not include any links, but keep issue numbers if present.
36
+
37
+ Important formatting instructions:
38
+ - Do not use any Markdown syntax (*, #, `, etc.)
39
+ - Use plain text only
40
+ - For section headers, simply use the text as is (e.g., "New Features:")
41
+ - For list items, use simple numbers or bullet points (•) followed by a space
42
+ - Keep the text structure simple and easy to convert to a Word document format
43
+ """
44
 
45
  response = model.generate_content(prompt)
46
+ release_notes = response.text
 
47
 
48
  doc = docx.Document()
49
  doc.add_heading('Release Notes', 0)
50
 
51
+ for line in release_notes.split('\n'):
52
+ if line.strip().endswith(':'):
53
+ doc.add_heading(line.strip(), level=1)
54
+ elif line.strip().startswith('•') or line.strip()[0].isdigit():
55
+ doc.add_paragraph(line.strip(), style='List Bullet')
56
+ else:
57
+ doc.add_paragraph(line)
58
 
59
  temp_file = "release_notes.docx"
60
  doc.save(temp_file)