Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import subprocess
|
| 4 |
import git
|
|
|
|
|
|
|
| 5 |
import zipfile
|
| 6 |
import io
|
| 7 |
from getpass import getpass
|
|
@@ -9,23 +10,7 @@ import radon.complexity as radon_complexity
|
|
| 9 |
import pylint.lint
|
| 10 |
from pylint.reporters.text import TextReporter
|
| 11 |
|
| 12 |
-
# Function to
|
| 13 |
-
def authenticate_github(token):
|
| 14 |
-
headers = {
|
| 15 |
-
"Authorization": f"token {token}"
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
# Fetch the list of repositories
|
| 19 |
-
response = requests.get("https://api.github.com/user/repos", headers=headers)
|
| 20 |
-
|
| 21 |
-
if response.status_code == 200:
|
| 22 |
-
repos = response.json()
|
| 23 |
-
repo_names = [repo['name'] for repo in repos]
|
| 24 |
-
return repo_names
|
| 25 |
-
else:
|
| 26 |
-
return "Error: Failed to fetch repositories"
|
| 27 |
-
|
| 28 |
-
# Function to download the repo as a zip file from GitHub API
|
| 29 |
def download_repo(github_url):
|
| 30 |
repo_name = github_url.split('/')[-1]
|
| 31 |
repo_owner = github_url.split('/')[-2]
|
|
@@ -111,5 +96,22 @@ def analyze_code(github_url, token=None):
|
|
| 111 |
|
| 112 |
return results
|
| 113 |
except Exception as e:
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import git
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
import zipfile
|
| 7 |
import io
|
| 8 |
from getpass import getpass
|
|
|
|
| 10 |
import pylint.lint
|
| 11 |
from pylint.reporters.text import TextReporter
|
| 12 |
|
| 13 |
+
# Function to download repo as a zip file from GitHub API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def download_repo(github_url):
|
| 15 |
repo_name = github_url.split('/')[-1]
|
| 16 |
repo_owner = github_url.split('/')[-2]
|
|
|
|
| 96 |
|
| 97 |
return results
|
| 98 |
except Exception as e:
|
| 99 |
+
return f"Error: {str(e)}"
|
| 100 |
+
|
| 101 |
+
# Create Gradio Interface
|
| 102 |
+
def gradio_interface():
|
| 103 |
+
gr.Interface(
|
| 104 |
+
fn=analyze_code,
|
| 105 |
+
inputs=[
|
| 106 |
+
gr.Textbox(label="GitHub Repository URL", placeholder="Enter the URL of the GitHub repo"),
|
| 107 |
+
gr.Textbox(label="GitHub Token (Optional)", type="password")
|
| 108 |
+
],
|
| 109 |
+
outputs="text",
|
| 110 |
+
live=True,
|
| 111 |
+
title="GitHub Code Quality Analyzer",
|
| 112 |
+
description="Enter a GitHub repository URL to analyze its code quality (complexity, linting, coverage, duplication)."
|
| 113 |
+
).launch(share=True)
|
| 114 |
+
|
| 115 |
+
gradio_interface()
|
| 116 |
+
|
| 117 |
|