Download repochat/git.py from rcs3/Codebot: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/rcs3/Codebot/resolve/main/repochat/git.py
- Command line
-
hf download hf://spaces/rcs3/Codebot/repochat/git.py
-
curl -L -o git.py https://huggingface.co/spaces/rcs3/Codebot/resolve/main/repochat/git.py
2.13 kB
| import re | |
| import requests | |
| import streamlit as st | |
| from .utils import clone_repo | |
| def parse_github_url(url: str): | |
| pattern = r"https?://github\.com/([^/]+)/([^/\s\.]+)" | |
| match = re.match(pattern, url.strip()) | |
| if not match: | |
| return None | |
| owner, repo = match.group(1), match.group(2) | |
| clean_url = f"https://github.com/{owner}/{repo}.git" | |
| return owner, repo, clean_url | |
| def git_form(repo_path): | |
| with st.sidebar: | |
| st.markdown("## 🔗 GitHub Repository") | |
| st.caption("Paste any public GitHub repo URL below.") | |
| git_url = st.text_input( | |
| "Repository URL", | |
| placeholder="https://github.com/owner/repo", | |
| key="github_url_input", | |
| ) | |
| submitted = st.button("🚀 Load Repository", use_container_width=True) | |
| if submitted: | |
| if not git_url.strip(): | |
| st.warning("Please enter a GitHub URL.") | |
| return None | |
| parsed = parse_github_url(git_url) | |
| if not parsed: | |
| st.error("Invalid GitHub URL. Expected: https://github.com/owner/repo") | |
| return None | |
| owner, repo, clone_url = parsed | |
| db_name = f"{owner}_{repo}" | |
| with st.spinner("Verifying repository…"): | |
| try: | |
| api_url = f"https://api.github.com/repos/{owner}/{repo}" | |
| resp = requests.get(api_url, timeout=10) | |
| if resp.status_code == 404: | |
| st.error("Repository not found. Make sure it is public.") | |
| return None | |
| if resp.status_code != 200: | |
| st.error(f"GitHub API error: {resp.status_code}") | |
| return None | |
| except requests.exceptions.RequestException as e: | |
| st.error(f"Network error: {e}") | |
| return None | |
| with st.spinner(f"Cloning `{owner}/{repo}`…"): | |
| clone_repo(clone_url, repo_path) | |
| st.success(f"✅ Cloned **{owner}/{repo}**") | |
| return db_name, True | |
| return None |