Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,59 @@ import json
|
|
6 |
from tenacity import retry, stop_after_attempt, wait_fixed
|
7 |
|
8 |
def fetch_github_files(github_url, personal_access_token):
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def process_chunk_with_gemini(chunk, gemini_api_key):
|
12 |
genai.configure(api_key=gemini_api_key)
|
|
|
6 |
from tenacity import retry, stop_after_attempt, wait_fixed
|
7 |
|
8 |
def fetch_github_files(github_url, personal_access_token):
|
9 |
+
try:
|
10 |
+
# Parse the GitHub URL
|
11 |
+
parts = github_url.split('/')
|
12 |
+
owner = parts[3]
|
13 |
+
repo = parts[4].split('.git')[0]
|
14 |
+
branch = 'main' # You might want to make this configurable
|
15 |
+
|
16 |
+
# List of common dependency files to look for
|
17 |
+
dependency_files = [
|
18 |
+
'requirements.txt',
|
19 |
+
'package.json',
|
20 |
+
'Gemfile',
|
21 |
+
'pom.xml',
|
22 |
+
'build.gradle',
|
23 |
+
'composer.json',
|
24 |
+
'Cargo.toml',
|
25 |
+
'go.mod',
|
26 |
+
'Pipfile'
|
27 |
+
]
|
28 |
+
|
29 |
+
all_content = ""
|
30 |
+
|
31 |
+
# Set up headers with the personal access token
|
32 |
+
headers = {
|
33 |
+
"Authorization": f"token {personal_access_token}",
|
34 |
+
"Accept": "application/vnd.github.v3+json"
|
35 |
+
}
|
36 |
+
|
37 |
+
for file_path in dependency_files:
|
38 |
+
# Construct the API URL
|
39 |
+
api_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{file_path}?ref={branch}"
|
40 |
+
|
41 |
+
# Make the API request
|
42 |
+
response = requests.get(api_url, headers=headers)
|
43 |
+
|
44 |
+
if response.status_code == 200:
|
45 |
+
content = response.json()
|
46 |
+
if isinstance(content, dict) and 'content' in content:
|
47 |
+
# This is a file
|
48 |
+
file_content = base64.b64decode(content['content']).decode('utf-8')
|
49 |
+
all_content += f"\n\n--- {file_path} ---\n{file_content}"
|
50 |
+
else:
|
51 |
+
# This is a directory or something else, skip it
|
52 |
+
continue
|
53 |
+
|
54 |
+
if not all_content:
|
55 |
+
return "Error: No dependency files found in the repository."
|
56 |
+
|
57 |
+
return all_content
|
58 |
+
except requests.exceptions.RequestException as e:
|
59 |
+
return f"Error accessing GitHub: {str(e)}"
|
60 |
+
except json.JSONDecodeError:
|
61 |
+
return f"Error: Unable to parse GitHub API response for {file_path}"
|
62 |
|
63 |
def process_chunk_with_gemini(chunk, gemini_api_key):
|
64 |
genai.configure(api_key=gemini_api_key)
|