bluenevus commited on
Commit
5c0a4f6
·
verified ·
1 Parent(s): 237ff07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -2,11 +2,11 @@ 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
@@ -25,6 +25,9 @@ def generate_release_notes(github_url, github_token, gemini_api_key, start_date,
25
  commit_messages = [commit.commit.message for commit in commits]
26
  commit_text = "\n".join(commit_messages)
27
 
 
 
 
28
  # Use Gemini AI to generate release notes
29
  genai.configure(api_key=gemini_api_key)
30
  model = genai.GenerativeModel('gemini-pro')
@@ -45,6 +48,13 @@ def generate_release_notes(github_url, github_token, gemini_api_key, start_date,
45
 
46
  return response.text
47
 
 
 
 
 
 
 
 
48
  except Exception as e:
49
  return f"An error occurred: {str(e)}"
50
 
 
2
  from datetime import datetime, timedelta
3
  import requests
4
  import google.generativeai as genai
5
+ from github import Github, GithubException
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
  # Extract owner and repo from the URL
 
25
  commit_messages = [commit.commit.message for commit in commits]
26
  commit_text = "\n".join(commit_messages)
27
 
28
+ if not commit_text:
29
+ return "No commits found in the specified date range."
30
+
31
  # Use Gemini AI to generate release notes
32
  genai.configure(api_key=gemini_api_key)
33
  model = genai.GenerativeModel('gemini-pro')
 
48
 
49
  return response.text
50
 
51
+ except GithubException as e:
52
+ if e.status == 401:
53
+ return "Error: Invalid GitHub token or insufficient permissions."
54
+ elif e.status == 404:
55
+ return "Error: Repository not found. Please check the GitHub URL."
56
+ else:
57
+ return f"GitHub API error: {str(e)}"
58
  except Exception as e:
59
  return f"An error occurred: {str(e)}"
60