File size: 2,116 Bytes
88d205f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Repository Input Component
This module provides the UI component for entering a GitHub repository URL.
"""
import gradio as gr
import re
import logging
logger = logging.getLogger(__name__)
def validate_github_url(url):
"""
Validate that the input is a proper GitHub repository URL.
Args:
url (str): The URL to validate.
Returns:
str or None: Error message if invalid, None if valid.
"""
if not url:
return None
# Basic GitHub URL pattern
pattern = r'^https?://github\.com/[\w.-]+/[\w.-]+/?$'
if not re.match(pattern, url):
return "Please enter a valid GitHub repository URL"
return None
def create_repo_input():
"""
Create the repository input component.
Returns:
tuple: (repo_url, github_token, submit_btn) - The repository URL input, GitHub token input, and submit button.
"""
with gr.Group():
gr.Markdown("### π GitHub Repository")
repo_url = gr.Textbox(
label="Repository URL",
placeholder="https://github.com/username/repository",
info="Enter the URL of a GitHub repository",
)
github_token = gr.Textbox(
label="GitHub Token (Optional)",
placeholder="For private repositories only",
info="Required only for private repositories",
type="password",
visible=True
)
submit_btn = gr.Button(
value="Analyze Repository",
variant="primary",
scale=0,
)
# Add validation for GitHub URL format
error_box = gr.Textbox(
label="Error",
visible=True,
interactive=False,
container=False,
show_label=False
)
repo_url.change(
fn=validate_github_url,
inputs=[repo_url],
outputs=[error_box],
show_progress=False
)
return repo_url, github_token, submit_btn |