1313 User ,
1414 WikiPage ,
1515 logging ,
16+ WorkflowRun ,
1617)
1718
1819
@@ -37,7 +38,7 @@ def get_user_data(self, user) -> User:
3738 return User (
3839 login = user .login ,
3940 username = user .name ,
40- email = user .email ,
41+ email = user .email , # always None
4142 html_url = user .html_url ,
4243 node_id = user .node_id ,
4344 type = user .type ,
@@ -46,6 +47,17 @@ def get_user_data(self, user) -> User:
4647 _id = user .id ,
4748 )
4849
50+ def get_commit_data (self , commit , files = False ) -> Commit :
51+ return Commit (
52+ _id = commit .sha ,
53+ message = commit .commit .message ,
54+ author = self .get_user_data (commit .author ),
55+ date = commit .commit .author .date ,
56+ files = [f .filename for f in commit .files ] if files else None ,
57+ additions = commit .stats .additions ,
58+ deletions = commit .stats .deletions ,
59+ )
60+
4961 def get_repository (self , id : str ) -> Repository | None :
5062 try :
5163 repo = self .client .get_repo (id )
@@ -66,18 +78,8 @@ def get_collaborator_permission(self, repo: Repository, user: User) -> str:
6678 def get_commits (self , repo : Repository , files : bool = True ) -> list [Commit ]:
6779 try :
6880 commits = self .client .get_repo (repo ._id ).get_commits ()
69- return [
70- Commit (
71- _id = c .sha ,
72- message = c .commit .message ,
73- author = self .get_user_data (c .author ),
74- date = c .commit .author .date ,
75- files = [f .filename for f in c .files ] if files else None ,
76- additions = c .stats .additions ,
77- deletions = c .stats .deletions ,
78- )
79- for c in commits
80- ]
81+ return [self .get_commit_data (c , files ) for c in commits ]
82+
8183 except Exception as e :
8284 logging .error (
8385 f"Failed to get commits from GitHub for repo { repo .name } : { e } "
@@ -153,18 +155,7 @@ def get_branches(self, repo: Repository) -> list[Branch]:
153155 for branch in branches :
154156 commit = repo_client .get_commit (branch .commit .sha )
155157
156- author = commit .author
157- contributor = Contributor (
158- username = author .login if author else "unknown" ,
159- email = commit .commit .author .email or "" ,
160- )
161-
162- commit_obj = Commit (
163- _id = commit .sha ,
164- message = commit .commit .message ,
165- author = contributor ,
166- date = commit .commit .author .date ,
167- )
158+ commit_obj = self .get_commit_data (commit )
168159
169160 result .append (Branch (name = branch .name , last_commit = commit_obj ))
170161
@@ -182,10 +173,21 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
182173 def get_forks (self , repo : Repository ) -> list [Repository ]:
183174 repo_client = self .client .get_repo (repo ._id )
184175 result = []
176+
185177 for r in repo_client .get_forks ():
178+ default_branch = (Branch (name = r .default_branch , last_commit = None ),)
179+ owner = (self .get_user_data (r .owner ),)
180+
186181 result .append (
187- Repository (_id = repo .full_name , name = repo .name , url = repo .html_url )
182+ Repository (
183+ _id = r .full_name ,
184+ name = r .name ,
185+ url = r .html_url ,
186+ default_branch = default_branch ,
187+ owner = owner ,
188+ )
188189 )
190+
189191 return result
190192
191193 def get_comments (self , repo , obj ) -> list [Comment ]:
@@ -246,6 +248,34 @@ def get_invites(self, repo: Repository) -> list[Invite]:
246248 def get_rate_limiting (self ) -> tuple [int , int ]:
247249 return self .client .rate_limiting
248250
251+ def get_workflow_runs (self , repo ) -> list [WorkflowRun ]:
252+ try :
253+ runs = self .client .get_repo (repo ._id ).get_workflow_runs ()
254+
255+ return [
256+ WorkflowRun (
257+ display_title = r .display_title ,
258+ event = r .event ,
259+ head_branch = r .head_branch ,
260+ head_sha = r .head_sha ,
261+ name = r .name ,
262+ path = r .path ,
263+ created_at = r .created_at ,
264+ run_started_at = r .run_started_at ,
265+ updated_at = r .updated_at ,
266+ conclusion = r .conclusion ,
267+ status = r .status ,
268+ url = r .url ,
269+ )
270+ for r in runs
271+ ]
272+
273+ except Exception as e :
274+ logging .error (
275+ f"Failed to get workflow runs from GitHub for repo { repo .name } : { e } "
276+ )
277+ return []
278+
249279
250280# Точка входа для тестирования
251281if __name__ == "__main__" :
0 commit comments