-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepo_manager.py
More file actions
39 lines (33 loc) · 1.28 KB
/
repo_manager.py
File metadata and controls
39 lines (33 loc) · 1.28 KB
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
import os
from pydriller import Repository
from git import Repo
from urllib.parse import urlparse
import logging
logger = logging.getLogger(__name__)
class RepoManager:
def __init__(self, repo_url, path='dataset/'):
self.repo_url = repo_url
self.repo_name = self.extract_repo_owner_and_name_from_url(repo_url)
self.clone_path = os.path.join(path, self.repo_name)
self.repo = None
def extract_repo_owner_and_name_from_url(self,repo_url):
try:
# Parse a URL para obter os componentes
path = urlparse(repo_url).path
# Divide o caminho para obter o owner
parts = path.strip('/').split('/')
if len(parts) >= 2:
return parts[0]+"_"+Repository(repo_url)._get_repo_name_from_url(repo_url)
else:
return Repository(repo_url)._get_repo_name_from_url(repo_url)
except Exception as e:
logger.error(f"Erro ao extrair owner: {str(e)}")
def clone_repo(self):
if not os.path.exists(self.clone_path):
self.repo = Repo.clone_from(self.repo_url, self.clone_path)
else:
self.repo = Repo(self.clone_path)
def get_repo(self):
return self.repo
def get_clone_path(self):
return self.clone_path