-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.py
More file actions
50 lines (40 loc) · 1.71 KB
/
Copy pathqueries.py
File metadata and controls
50 lines (40 loc) · 1.71 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
40
41
42
43
44
45
46
47
48
49
50
from typing import List
from core.interfaces.git_client import GitClient
from core.interfaces.query_client import QueryClient
from entities.repos import Repo
from core.files.queries.models import FileQueryModel
class FilesQueries:
def __init__(self, git_client: GitClient, query_client: QueryClient) -> None:
"""
Initialize the FilesQueries class.
This class is responsible for executing queries related to repositories.
Args:
git_client (GitClient): An instance of GitClient for Git operations.
query_client (QueryClient): An instance of QueryClient for database operations.
"""
self.git_client = git_client
self.query_client = query_client
def get_file_history(self, file_path: str, repo_name: str) -> List[FileQueryModel]:
"""
Returns the history of a file in the repository.
Args:
file_path (str): The path to the file within the repository.
repo_name (str): The path to the repository.
"""
with self.query_client.session() as session:
repo: Repo | None = (
session.query(Repo).filter(Repo.name == repo_name).one_or_none()
)
if not repo:
return []
results = []
for commit in self.git_client.iter_file_history(file_path, repo.path):
results.append(
FileQueryModel(
commit_hash=commit.hexsha,
message=commit.message.strip(),
author=commit.author.name,
date=commit.committed_datetime.isoformat(),
)
)
return results