Update app.py
Browse files
app.py
CHANGED
|
@@ -2,20 +2,39 @@ import gradio as gr
|
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
import google.generativeai as genai
|
| 4 |
from github import Github, GithubException
|
|
|
|
| 5 |
import docx
|
| 6 |
import tempfile
|
|
|
|
| 7 |
|
| 8 |
-
def generate_release_notes(
|
| 9 |
try:
|
| 10 |
-
g = Github(github_token)
|
| 11 |
-
|
| 12 |
-
repo = g.get_repo(github_repo)
|
| 13 |
-
|
| 14 |
start_date = datetime.strptime(start_date, "%Y-%m-%d")
|
| 15 |
end_date = datetime.strptime(end_date, "%Y-%m-%d")
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
commit_text = "\n".join(commit_messages)
|
| 20 |
|
| 21 |
if not commit_text:
|
|
@@ -81,13 +100,6 @@ def generate_release_notes(github_repo, github_token, gemini_api_key, start_date
|
|
| 81 |
|
| 82 |
return release_notes, docx_path, md_path
|
| 83 |
|
| 84 |
-
except GithubException as e:
|
| 85 |
-
if e.status == 401:
|
| 86 |
-
return "Error: Invalid GitHub token or insufficient permissions.", None, None
|
| 87 |
-
elif e.status == 404:
|
| 88 |
-
return f"Error: Repository not found. Please check the GitHub repository name. Attempted to access: {github_repo}", None, None
|
| 89 |
-
else:
|
| 90 |
-
return f"GitHub API error: {str(e)}", None, None
|
| 91 |
except Exception as e:
|
| 92 |
return f"An error occurred: {str(e)}", None, None
|
| 93 |
|
|
@@ -97,8 +109,12 @@ default_start_date = default_end_date - timedelta(days=30)
|
|
| 97 |
iface = gr.Interface(
|
| 98 |
fn=generate_release_notes,
|
| 99 |
inputs=[
|
| 100 |
-
gr.
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
gr.Textbox(label="Gemini API Key", type="password"),
|
| 103 |
gr.Textbox(
|
| 104 |
label="Start Date",
|
|
@@ -117,7 +133,7 @@ iface = gr.Interface(
|
|
| 117 |
gr.File(label="Download Release Notes (Markdown)")
|
| 118 |
],
|
| 119 |
title="Automated Release Notes Generator",
|
| 120 |
-
description="Generate release notes based on
|
| 121 |
allow_flagging="never",
|
| 122 |
theme="default",
|
| 123 |
analytics_enabled=False,
|
|
|
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
import google.generativeai as genai
|
| 4 |
from github import Github, GithubException
|
| 5 |
+
import gitlab
|
| 6 |
import docx
|
| 7 |
import tempfile
|
| 8 |
+
import requests
|
| 9 |
|
| 10 |
+
def generate_release_notes(git_provider, repo_url, personal_access_token, gemini_api_key, start_date, end_date):
|
| 11 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
start_date = datetime.strptime(start_date, "%Y-%m-%d")
|
| 13 |
end_date = datetime.strptime(end_date, "%Y-%m-%d")
|
| 14 |
+
|
| 15 |
+
if git_provider == "GitHub":
|
| 16 |
+
g = Github(personal_access_token)
|
| 17 |
+
repo = g.get_repo(repo_url)
|
| 18 |
+
commits = list(repo.get_commits(since=start_date, until=end_date))
|
| 19 |
+
commit_messages = [commit.commit.message for commit in commits]
|
| 20 |
+
elif git_provider == "GitLab":
|
| 21 |
+
gl = gitlab.Gitlab(url='https://gitlab.com', private_token=personal_access_token)
|
| 22 |
+
project = gl.projects.get(repo_url)
|
| 23 |
+
commits = project.commits.list(since=start_date.isoformat(), until=end_date.isoformat())
|
| 24 |
+
commit_messages = [commit.message for commit in commits]
|
| 25 |
+
elif git_provider == "Gitea":
|
| 26 |
+
base_url = "https://gitea.com/api/v1"
|
| 27 |
+
headers = {"Authorization": f"token {personal_access_token}"}
|
| 28 |
+
response = requests.get(f"{base_url}/repos/{repo_url}/commits", headers=headers, params={
|
| 29 |
+
"since": start_date.isoformat(),
|
| 30 |
+
"until": end_date.isoformat()
|
| 31 |
+
})
|
| 32 |
+
response.raise_for_status()
|
| 33 |
+
commits = response.json()
|
| 34 |
+
commit_messages = [commit['commit']['message'] for commit in commits]
|
| 35 |
+
else:
|
| 36 |
+
return "Unsupported Git provider", None, None
|
| 37 |
+
|
| 38 |
commit_text = "\n".join(commit_messages)
|
| 39 |
|
| 40 |
if not commit_text:
|
|
|
|
| 100 |
|
| 101 |
return release_notes, docx_path, md_path
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
except Exception as e:
|
| 104 |
return f"An error occurred: {str(e)}", None, None
|
| 105 |
|
|
|
|
| 109 |
iface = gr.Interface(
|
| 110 |
fn=generate_release_notes,
|
| 111 |
inputs=[
|
| 112 |
+
gr.Dropdown(
|
| 113 |
+
choices=["GitHub", "GitLab", "Gitea"],
|
| 114 |
+
label="Git Provider"
|
| 115 |
+
),
|
| 116 |
+
gr.Textbox(label="Repository URL", placeholder="owner/repo"),
|
| 117 |
+
gr.Textbox(label="Personal Access Token", type="password"),
|
| 118 |
gr.Textbox(label="Gemini API Key", type="password"),
|
| 119 |
gr.Textbox(
|
| 120 |
label="Start Date",
|
|
|
|
| 133 |
gr.File(label="Download Release Notes (Markdown)")
|
| 134 |
],
|
| 135 |
title="Automated Release Notes Generator",
|
| 136 |
+
description="Generate release notes based on Git commits using Gemini AI. Select a Git provider, enter repository details, and specify the date range for commits.",
|
| 137 |
allow_flagging="never",
|
| 138 |
theme="default",
|
| 139 |
analytics_enabled=False,
|