1111)
1212from github import Github
1313
14+
1415class GitHubRepoAPI (IRepositoryAPI ):
15-
16+
1617 def __init__ (self , client ):
1718 self .client = client
1819
@@ -31,20 +32,27 @@ def get_commits(self, repo: Repository) -> list[Commit]:
3132 Commit (
3233 _id = c .sha ,
3334 message = c .commit .message ,
34- author = Contributor (c .author .login if c .author else "unknown" , c .commit .author .email ),
35- date = c .commit .author .date
36- ) for c in commits
35+ author = Contributor (
36+ c .author .login if c .author else "unknown" , c .commit .author .email
37+ ),
38+ date = c .commit .author .date ,
39+ )
40+ for c in commits
3741 ]
3842 except Exception as e :
39- logging .error (f"Failed to get commits from GitHub for repo { repo .name } : { e } " )
43+ logging .error (
44+ f"Failed to get commits from GitHub for repo { repo .name } : { e } "
45+ )
4046 return []
4147
4248 def get_contributors (self , repo : Repository ) -> list [Contributor ]:
4349 try :
4450 contributors = self .client .get_repo (repo ._id ).get_contributors ()
4551 return [Contributor (c .login , c .email or "" ) for c in contributors ]
4652 except Exception as e :
47- logging .error (f"Failed to get contributors from GitHub for repo { repo .name } : { e } " )
53+ logging .error (
54+ f"Failed to get contributors from GitHub for repo { repo .name } : { e } "
55+ )
4856 return []
4957
5058 def get_issues (self , repo : Repository ) -> list [Issue ]:
@@ -55,8 +63,9 @@ def get_issues(self, repo: Repository) -> list[Issue]:
5563 _id = i .number ,
5664 title = i .title ,
5765 author = Contributor (i .user .login , i .user .email or "" ),
58- state = i .state
59- ) for i in issues
66+ state = i .state ,
67+ )
68+ for i in issues
6069 ]
6170 except Exception as e :
6271 logging .error (f"Failed to get issues from GitHub for repo { repo .name } : { e } " )
@@ -70,47 +79,46 @@ def get_pull_requests(self, repo: Repository) -> list[PullRequest]:
7079 _id = p .number ,
7180 title = p .title ,
7281 author = Contributor (p .user .login , p .user .email or "" ),
73- state = p .state
74- ) for p in pulls
82+ state = p .state ,
83+ )
84+ for p in pulls
7585 ]
7686 except Exception as e :
77- logging .error (f"Failed to get pull requests from GitHub for repo { repo .name } : { e } " )
87+ logging .error (
88+ f"Failed to get pull requests from GitHub for repo { repo .name } : { e } "
89+ )
7890 return []
79-
91+
8092 def get_branches (self , repo : Repository ) -> list [Branch ]:
8193 try :
8294 repo_client = self .client .get_repo (repo ._id )
8395 branches = repo_client .get_branches ()
8496 result = []
85-
97+
8698 for branch in branches :
8799 commit = repo_client .get_commit (branch .commit .sha )
88-
89-
100+
90101 author = commit .author
91102 contributor = Contributor (
92103 username = author .login if author else "unknown" ,
93- email = commit .commit .author .email or ""
104+ email = commit .commit .author .email or "" ,
94105 )
95-
106+
96107 commit_obj = Commit (
97108 _id = commit .sha ,
98109 message = commit .commit .message ,
99110 author = contributor ,
100- date = commit .commit .author .date
111+ date = commit .commit .author .date ,
101112 )
102-
103- result .append (
104- Branch (
105- name = branch .name ,
106- last_commit = commit_obj
107- )
108- )
109-
113+
114+ result .append (Branch (name = branch .name , last_commit = commit_obj ))
115+
110116 return result
111-
117+
112118 except Exception as e :
113- logging .error (f"Failed to get branches from GitHub for repo { repo .name } : { e } " )
119+ logging .error (
120+ f"Failed to get branches from GitHub for repo { repo .name } : { e } "
121+ )
114122 return []
115123
116124 def get_wiki_pages (self , repo : Repository ) -> list [WikiPage ]:
@@ -123,7 +131,7 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
123131 client = Github ("tocken" )
124132 api = GitHubRepoAPI (client )
125133
126- # Укажите ваш репозиторий
134+ # Укажите ваш репозиторий
127135 repo_name = ""
128136
129137 # Получение репозитория
@@ -139,7 +147,9 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
139147 commits = api .get_commits (repo )
140148 print (f"Total commits: { len (commits )} " )
141149 for commit in commits [:10 ]: # Выведем первые 10 коммитов
142- print (f"Commit: { commit ._id } , Message: { commit .message } , Author: { commit .author .username } " )
150+ print (
151+ f"Commit: { commit ._id } , Message: { commit .message } , Author: { commit .author .username } "
152+ )
143153
144154 # Получение контрибьюторов
145155 contributors = api .get_contributors (repo )
@@ -159,9 +169,10 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
159169 for pull in pulls [:10 ]: # Выведем первые 10 pull requests
160170 print (f"Pull Request: { pull ._id } , Title: { pull .title } , State: { pull .state } " )
161171
162-
163172 # Получение веток
164173 branches = api .get_branches (repo )
165174 print (f"Total branches: { len (branches )} " )
166175 for branch in branches :
167- print (f"Branch: { branch .name } , Last Commit: { branch .last_commit ._id if branch .last_commit else 'None' } " )
176+ print (
177+ f"Branch: { branch .name } , Last Commit: { branch .last_commit ._id if branch .last_commit else 'None' } "
178+ )
0 commit comments