bluenevus commited on
Commit
93d3e19
·
verified ·
1 Parent(s): e7c32a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -9
app.py CHANGED
@@ -3,28 +3,49 @@ from datetime import datetime, timedelta
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:
9
- # Initialize GitHub client with the token
10
  g = Github(github_token)
11
-
12
- # Get the repository directly using the full URL
13
  repo = g.get_repo(github_url)
14
 
15
- # Get commits between start_date and end_date
16
  start_date = datetime.strptime(start_date, "%Y-%m-%d")
17
  end_date = datetime.strptime(end_date, "%Y-%m-%d")
18
  commits = list(repo.get_commits(since=start_date, until=end_date))
19
 
20
- # Prepare commit messages
21
  commit_messages = [commit.commit.message for commit in commits]
22
  commit_text = "\n".join(commit_messages)
23
 
24
  if not commit_text:
25
  return "No commits found in the specified date range.", None
26
 
27
- # Use Gemini AI to generate release notes
28
  genai.configure(api_key=gemini_api_key)
29
  model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
30
 
@@ -38,20 +59,25 @@ def generate_release_notes(github_url, github_token, gemini_api_key, start_date,
38
  3. Improvements
39
  4. Breaking Changes (if any)
40
 
41
- Provide a concise summary for each item."""
42
 
43
  response = model.generate_content(prompt)
44
 
 
 
 
45
  # Create a Word document
46
  doc = docx.Document()
47
  doc.add_heading('Release Notes', 0)
48
- doc.add_paragraph(response.text)
 
 
49
 
50
  # Save the document to a temporary file
51
  temp_file = "release_notes.docx"
52
  doc.save(temp_file)
53
 
54
- return response.text, temp_file
55
 
56
  except GithubException as e:
57
  if e.status == 401:
 
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
+ # Remove links but keep issue numbers
10
+ return re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', text)
11
+
12
+ def markdown_to_docx(doc, markdown_text):
13
+ # Split the markdown into lines
14
+ lines = markdown_text.split('\n')
15
+
16
+ for line in lines:
17
+ # Check for headers
18
+ if line.startswith('# '):
19
+ doc.add_heading(line[2:], level=1)
20
+ elif line.startswith('## '):
21
+ doc.add_heading(line[3:], level=2)
22
+ elif line.startswith('### '):
23
+ doc.add_heading(line[4:], level=3)
24
+ # Check for list items
25
+ elif line.strip().startswith('- ') or line.strip().startswith('* '):
26
+ doc.add_paragraph(line.strip()[2:], style='List Bullet')
27
+ # Check for numbered list items
28
+ elif re.match(r'^\d+\.', line.strip()):
29
+ doc.add_paragraph(line.strip(), style='List Number')
30
+ # Regular paragraph
31
+ else:
32
+ doc.add_paragraph(line)
33
 
34
  def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
35
  try:
 
36
  g = Github(github_token)
 
 
37
  repo = g.get_repo(github_url)
38
 
 
39
  start_date = datetime.strptime(start_date, "%Y-%m-%d")
40
  end_date = datetime.strptime(end_date, "%Y-%m-%d")
41
  commits = list(repo.get_commits(since=start_date, until=end_date))
42
 
 
43
  commit_messages = [commit.commit.message for commit in commits]
44
  commit_text = "\n".join(commit_messages)
45
 
46
  if not commit_text:
47
  return "No commits found in the specified date range.", None
48
 
 
49
  genai.configure(api_key=gemini_api_key)
50
  model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
51
 
 
59
  3. Improvements
60
  4. Breaking Changes (if any)
61
 
62
+ Provide a concise summary for each item. Do not include any links, but keep issue numbers if present."""
63
 
64
  response = model.generate_content(prompt)
65
 
66
+ # Remove links but keep issue numbers
67
+ release_notes = remove_links_keep_issue_numbers(response.text)
68
+
69
  # Create a Word document
70
  doc = docx.Document()
71
  doc.add_heading('Release Notes', 0)
72
+
73
+ # Convert markdown to docx
74
+ markdown_to_docx(doc, release_notes)
75
 
76
  # Save the document to a temporary file
77
  temp_file = "release_notes.docx"
78
  doc.save(temp_file)
79
 
80
+ return release_notes, temp_file
81
 
82
  except GithubException as e:
83
  if e.status == 401: