Skip to content

Commit 8801ef8

Browse files
committed
fixed imports
1 parent 27fe497 commit 8801ef8

File tree

1 file changed

+37
-112
lines changed

1 file changed

+37
-112
lines changed

GitHubRepoAPI.py

Lines changed: 37 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,16 @@
1-
from github import Github
2-
from typing import Optional, List
3-
import logging
4-
from datetime import datetime
5-
from dataclasses import dataclass
6-
from abc import ABC, abstractmethod
7-
8-
# Настройка логирования
9-
logging.basicConfig(
10-
level=logging.INFO,
11-
format="%(asctime)s - %(levelname)s - %(message)s"
1+
from interface_wrapper import (
2+
logging,
3+
Repository,
4+
Contributor,
5+
Commit,
6+
Issue,
7+
PullRequest,
8+
WikiPage,
9+
Branch,
10+
IRepositoryAPI,
1211
)
13-
14-
# Модельные классы
15-
@dataclass
16-
class Repository:
17-
_id: str
18-
name: str
19-
url: str
20-
21-
@dataclass
22-
class Contributor:
23-
username: str
24-
email: str
25-
26-
@dataclass
27-
class Commit:
28-
_id: str
29-
message: str
30-
author: Contributor
31-
date: datetime
32-
33-
@dataclass
34-
class Issue:
35-
_id: int
36-
title: str
37-
author: Contributor
38-
state: str
39-
40-
@dataclass
41-
class PullRequest:
42-
_id: int
43-
title: str
44-
author: Contributor
45-
state: str
46-
47-
@dataclass
48-
class WikiPage:
49-
title: str
50-
content: str
51-
52-
@dataclass
53-
class Branch:
54-
name: str
55-
last_commit: Commit | None
56-
57-
# Интерфейс API
58-
class IRepositoryAPI(ABC):
59-
@abstractmethod
60-
def get_repository(self, id: str) -> Repository | None:
61-
"""Получить репозиторий по его идентификатору."""
62-
pass
63-
64-
@abstractmethod
65-
def get_commits(self, repo: Repository) -> list[Commit]:
66-
"""Получить список коммитов для репозитория."""
67-
pass
68-
69-
@abstractmethod
70-
def get_contributors(self, repo: Repository) -> list[Contributor]:
71-
"""Получить список контрибьюторов для репозитория."""
72-
pass
73-
74-
@abstractmethod
75-
def get_issues(self, repo: Repository) -> list[Issue]:
76-
"""Получить список issues для репозитория."""
77-
pass
78-
79-
@abstractmethod
80-
def get_pull_requests(self, repo: Repository) -> list[PullRequest]:
81-
"""Получить список pull requests для репозитория."""
82-
pass
83-
84-
@abstractmethod
85-
def get_branches(self, repo: Repository) -> list[Branch]:
86-
"""Получить список веток для репозитория."""
87-
pass
88-
89-
@abstractmethod
90-
def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
91-
"""Получить список wiki-страниц для репозитория."""
92-
pass
93-
12+
from typing import Optional, List
13+
from github import Github
9414

9515
class GitHubRepoAPI(IRepositoryAPI):
9616

@@ -100,20 +20,20 @@ def __init__(self, client):
10020
def get_repository(self, id: str) -> Optional[Repository]:
10121
try:
10222
repo = self.client.get_repo(id)
103-
return Repository(repo.full_name, repo.name, repo.html_url)
23+
return Repository(_id=repo.full_name, name=repo.name, url=repo.html_url)
10424
except Exception as e:
10525
logging.error(f"Failed to get repository {id} from GitHub: {e}")
10626
return None
10727

10828
def get_commits(self, repo: Repository) -> List[Commit]:
10929
try:
110-
commits = self.client.get_repo(repo.id).get_commits()
30+
commits = self.client.get_repo(repo._id).get_commits()
11131
return [
11232
Commit(
113-
c.sha,
114-
c.commit.message,
115-
Contributor(c.author.login if c.author else "unknown", c.commit.author.email),
116-
c.commit.author.date
33+
_id=c.sha,
34+
message=c.commit.message,
35+
author=Contributor(c.author.login if c.author else "unknown", c.commit.author.email),
36+
date=c.commit.author.date
11737
) for c in commits
11838
]
11939
except Exception as e:
@@ -122,52 +42,57 @@ def get_commits(self, repo: Repository) -> List[Commit]:
12242

12343
def get_contributors(self, repo: Repository) -> List[Contributor]:
12444
try:
125-
contributors = self.client.get_repo(repo.id).get_contributors()
45+
contributors = self.client.get_repo(repo._id).get_contributors()
12646
return [Contributor(c.login, c.email or "") for c in contributors]
12747
except Exception as e:
12848
logging.error(f"Failed to get contributors from GitHub for repo {repo.name}: {e}")
12949
return []
13050

13151
def get_issues(self, repo: Repository) -> List[Issue]:
13252
try:
133-
issues = self.client.get_repo(repo.id).get_issues(state='all')
53+
issues = self.client.get_repo(repo._id).get_issues(state='all')
13454
return [
13555
Issue(
136-
i.number,
137-
i.title,
138-
Contributor(i.user.login, i.user.email or ""),
139-
i.state
56+
_id=i.number,
57+
title=i.title,
58+
author=Contributor(i.user.login, i.user.email or ""),
59+
state=i.state
14060
) for i in issues
14161
]
14262
except Exception as e:
14363
logging.error(f"Failed to get issues from GitHub for repo {repo.name}: {e}")
14464
return []
145-
14665

14766
def get_pull_requests(self, repo: Repository) -> List[PullRequest]:
14867
try:
149-
pulls = self.client.get_repo(repo.id).get_pulls(state='all')
68+
pulls = self.client.get_repo(repo._id).get_pulls(state='all')
15069
return [
15170
PullRequest(
152-
p.number,
153-
p.title,
154-
Contributor(p.user.login, p.user.email or ""),
155-
p.state
71+
_id=p.number,
72+
title=p.title,
73+
author=Contributor(p.user.login, p.user.email or ""),
74+
state=p.state
15675
) for p in pulls
15776
]
15877
except Exception as e:
15978
logging.error(f"Failed to get pull requests from GitHub for repo {repo.name}: {e}")
16079
return []
16180

81+
def get_branches(self, repo: Repository) -> List[Branch]:
82+
pass
83+
84+
def get_wiki_pages(self, repo: Repository) -> List[WikiPage]:
85+
pass
86+
16287

16388
# Точка входа для тестирования
16489
if __name__ == "__main__":
165-
#клиент GitHub (используйте ваш токен)
90+
# Создайте клиент GitHub (используйте ваш токен)
16691
client = Github("tocken")
16792
api = GitHubRepoAPI(client)
16893

16994
# Укажите ваш репозиторий
170-
repo_name = "ваш_username/ваш_repo"
95+
repo_name = ""
17196

17297
# Получение репозитория
17398
repo = api.get_repository(repo_name)

0 commit comments

Comments
 (0)