Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,60 @@
|
|
1 |
import gradio as gr
|
2 |
from datetime import datetime, timedelta
|
|
|
|
|
|
|
3 |
|
4 |
def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
|
5 |
-
# This is a placeholder implementation. In a real scenario, you would use these
|
6 |
-
# parameters to fetch data from GitHub and generate release notes using Gemini AI.
|
7 |
try:
|
8 |
-
|
9 |
-
|
10 |
-
days = (end - start).days
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
notes += "1. New Features:\n - Feature A added\n - Feature B implemented\n\n"
|
15 |
-
notes += "2. Bug Fixes:\n - Fixed issue with login\n - Resolved performance problem in module X\n\n"
|
16 |
-
notes += "3. Improvements:\n - Enhanced user interface\n - Optimized database queries\n\n"
|
17 |
-
notes += "Note: This is a simulated output. Actual implementation would use GitHub API and Gemini AI."
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Set default dates
|
24 |
default_end_date = datetime.now()
|
25 |
-
default_start_date = default_end_date - timedelta(days=
|
26 |
|
27 |
# Create Gradio interface
|
28 |
iface = gr.Interface(
|
29 |
fn=generate_release_notes,
|
30 |
inputs=[
|
31 |
-
gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repo
|
32 |
gr.Textbox(label="GitHub Personal Access Token", type="password"),
|
33 |
gr.Textbox(label="Gemini API Key", type="password"),
|
34 |
gr.Textbox(
|
|
|
1 |
import gradio as gr
|
2 |
from datetime import datetime, timedelta
|
3 |
+
import requests
|
4 |
+
import google.generativeai as genai
|
5 |
+
from github import Github
|
6 |
|
7 |
def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
|
|
|
|
|
8 |
try:
|
9 |
+
# Initialize GitHub client
|
10 |
+
g = Github(github_token)
|
|
|
11 |
|
12 |
+
# Extract owner and repo from the URL
|
13 |
+
_, _, _, owner, repo = github_url.rstrip('/').split('/')
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Get the repository
|
16 |
+
repo = g.get_repo(f"{owner}/{repo}")
|
17 |
+
|
18 |
+
# Get commits between start_date and end_date
|
19 |
+
commits = repo.get_commits(since=datetime.strptime(start_date, "%Y-%m-%d"),
|
20 |
+
until=datetime.strptime(end_date, "%Y-%m-%d"))
|
21 |
+
|
22 |
+
# Prepare commit messages
|
23 |
+
commit_messages = [commit.commit.message for commit in commits]
|
24 |
+
commit_text = "\n".join(commit_messages)
|
25 |
+
|
26 |
+
# Use Gemini AI to generate release notes
|
27 |
+
genai.configure(api_key=gemini_api_key)
|
28 |
+
model = genai.GenerativeModel('gemini-pro')
|
29 |
+
|
30 |
+
prompt = f"""Based on the following commit messages, generate comprehensive release notes:
|
31 |
+
|
32 |
+
{commit_text}
|
33 |
+
|
34 |
+
Please organize the release notes into sections such as:
|
35 |
+
1. New Features
|
36 |
+
2. Bug Fixes
|
37 |
+
3. Improvements
|
38 |
+
4. Breaking Changes (if any)
|
39 |
+
|
40 |
+
Provide a concise summary for each item."""
|
41 |
+
|
42 |
+
response = model.generate_content(prompt)
|
43 |
+
|
44 |
+
return response.text
|
45 |
+
|
46 |
+
except Exception as e:
|
47 |
+
return f"An error occurred: {str(e)}"
|
48 |
|
49 |
# Set default dates
|
50 |
default_end_date = datetime.now()
|
51 |
+
default_start_date = default_end_date - timedelta(days=30) # One week ago
|
52 |
|
53 |
# Create Gradio interface
|
54 |
iface = gr.Interface(
|
55 |
fn=generate_release_notes,
|
56 |
inputs=[
|
57 |
+
gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repo"),
|
58 |
gr.Textbox(label="GitHub Personal Access Token", type="password"),
|
59 |
gr.Textbox(label="Gemini API Key", type="password"),
|
60 |
gr.Textbox(
|