Skip to content

Commit 27fe497

Browse files
committed
added: Class test
1 parent 038866c commit 27fe497

File tree

1 file changed

+138
-1
lines changed

1 file changed

+138
-1
lines changed

GitHubRepoAPI.py

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,97 @@
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"
12+
)
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+
94+
195
class GitHubRepoAPI(IRepositoryAPI):
296

397
def __init__(self, client):
@@ -63,4 +157,47 @@ def get_pull_requests(self, repo: Repository) -> List[PullRequest]:
63157
]
64158
except Exception as e:
65159
logging.error(f"Failed to get pull requests from GitHub for repo {repo.name}: {e}")
66-
return []
160+
return []
161+
162+
163+
# Точка входа для тестирования
164+
if __name__ == "__main__":
165+
#клиент GitHub (используйте ваш токен)
166+
client = Github("tocken")
167+
api = GitHubRepoAPI(client)
168+
169+
# Укажите ваш репозиторий
170+
repo_name = "ваш_username/ваш_repo"
171+
172+
# Получение репозитория
173+
repo = api.get_repository(repo_name)
174+
if not repo:
175+
print("Repository not found.")
176+
exit()
177+
178+
# Вывод информации о репозитории
179+
print(f"Repository: {repo.name}, URL: {repo.url}")
180+
181+
# Получение коммитов
182+
commits = api.get_commits(repo)
183+
print(f"Total commits: {len(commits)}")
184+
for commit in commits[:10]: # Выведем первые 10 коммитов
185+
print(f"Commit: {commit._id}, Message: {commit.message}, Author: {commit.author.username}")
186+
187+
# Получение контрибьюторов
188+
contributors = api.get_contributors(repo)
189+
print(f"Total contributors: {len(contributors)}")
190+
for contributor in contributors:
191+
print(f"Contributor: {contributor.username}, Email: {contributor.email}")
192+
193+
# Получение issues
194+
issues = api.get_issues(repo)
195+
print(f"Total issues: {len(issues)}")
196+
for issue in issues[:10]: # Выведем первые 10 issues
197+
print(f"Issue: {issue._id}, Title: {issue.title}, State: {issue.state}")
198+
199+
# Получение pull requests
200+
pulls = api.get_pull_requests(repo)
201+
print(f"Total pull requests: {len(pulls)}")
202+
for pull in pulls[:10]: # Выведем первые 10 pull requests
203+
print(f"Pull Request: {pull._id}, Title: {pull.title}, State: {pull.state}")

0 commit comments

Comments
 (0)