codeanalyze / app.py
kevin1911's picture
Update app.py
919814e verified
raw
history blame
1.96 kB
import gradio as gr
import requests
# Function to fetch repository details from GitHub
def analyze_github_repo(repo_url):
# Extract the username and repo name from the GitHub URL
if "github.com" not in repo_url:
return "Please provide a valid GitHub repository URL."
parts = repo_url.split('/')
if len(parts) < 5:
return "URL should be in the format: https://github.com/username/repository"
user, repo = parts[3], parts[4]
# GitHub API endpoint to get repository details
api_url = f"https://api.github.com/repos/{user}/{repo}"
response = requests.get(api_url)
# Check if repository exists
if response.status_code == 404:
return "Repository not found."
# Parse the response
data = response.json()
# Extract relevant information
stars = data.get('stargazers_count', 'N/A')
forks = data.get('forks_count', 'N/A')
issues = data.get('open_issues_count', 'N/A')
contributors_url = data.get('contributors_url', None)
# Get number of contributors
contributors = "N/A"
if contributors_url:
contributors_data = requests.get(contributors_url).json()
contributors = len(contributors_data)
# Return the analysis result
result = (
f"Repository: {repo_url}\n"
f"Stars: {stars}\n"
f"Forks: {forks}\n"
f"Open Issues: {issues}\n"
f"Contributors: {contributors}"
)
return result
# Gradio interface for the tool
iface = gr.Interface(
fn=analyze_github_repo,
inputs=gr.Textbox(label="Enter GitHub Repository URL", placeholder="https://github.com/username/repository"),
outputs=gr.Textbox(label="Repository Analysis", placeholder="Analysis will be displayed here..."),
title="GitHub Repository Analysis Tool",
description="Enter a GitHub repository URL to get basic analytics including stars, forks, issues, and contributors."
)
# Launch the app
iface.launch()