MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / GitHubRepoProcessor

Class GitHubRepoProcessor

codewiki/src/fe/github_processor.py:14–93  ·  view source on GitHub ↗

Handles GitHub repository processing.

Source from the content-addressed store, hash-verified

12
13
14class GitHubRepoProcessor:
15 """Handles GitHub repository processing."""
16
17 @staticmethod
18 def is_valid_github_url(url: str) -> bool:
19 """Validate if the URL is a valid GitHub repository URL."""
20 try:
21 parsed = urlparse(url)
22 if parsed.netloc.lower() not in ['github.com', 'www.github.com']:
23 return False
24
25 path_parts = parsed.path.strip('/').split('/')
26 if len(path_parts) < 2:
27 return False
28
29 # Check if it's a valid repo path (owner/repo)
30 return len(path_parts) >= 2 and all(part for part in path_parts[:2])
31 except Exception:
32 return False
33
34 @staticmethod
35 def get_repo_info(url: str) -> Dict[str, str]:
36 """Extract repository information from GitHub URL."""
37 parsed = urlparse(url)
38 path_parts = parsed.path.strip('/').split('/')
39
40 owner = path_parts[0]
41 repo = path_parts[1]
42
43 # Remove .git suffix if present
44 if repo.endswith('.git'):
45 repo = repo[:-4]
46
47 return {
48 'owner': owner,
49 'repo': repo,
50 'full_name': f"{owner}/{repo}",
51 'clone_url': f"https://github.com/{owner}/{repo}.git"
52 }
53
54 @staticmethod
55 def clone_repository(clone_url: str, target_dir: str, commit_id: str = None) -> bool:
56 """Clone a GitHub repository to the target directory, optionally checking out a specific commit."""
57 try:
58 # Ensure target directory exists
59 os.makedirs(os.path.dirname(target_dir), exist_ok=True)
60
61 # If specific commit is requested, don't use shallow clone
62 if commit_id:
63 # Clone full repository to access specific commit
64 result = subprocess.run([
65 'git', 'clone', clone_url, target_dir
66 ], capture_output=True, text=True, timeout=WebAppConfig.CLONE_TIMEOUT)
67
68 if result.returncode != 0:
69 print(f"Error cloning repository: {result.stderr}")
70 return False
71

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected