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,7 @@ 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 ]
8182 except Exception as e :
8283 logging .error (
8384 f"Failed to get commits from GitHub for repo { repo .name } : { e } "
@@ -153,18 +154,7 @@ def get_branches(self, repo: Repository) -> list[Branch]:
153154 for branch in branches :
154155 commit = repo_client .get_commit (branch .commit .sha )
155156
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- )
157+ commit_obj = self .get_commit_data (commit )
168158
169159 result .append (Branch (name = branch .name , last_commit = commit_obj ))
170160
@@ -182,10 +172,21 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
182172 def get_forks (self , repo : Repository ) -> list [Repository ]:
183173 repo_client = self .client .get_repo (repo ._id )
184174 result = []
175+
185176 for r in repo_client .get_forks ():
177+ default_branch = (Branch (name = r .default_branch , last_commit = None ),)
178+ owner = (self .get_user_data (r .owner ),)
179+
186180 result .append (
187- Repository (_id = repo .full_name , name = repo .name , url = repo .html_url )
181+ Repository (
182+ _id = r .full_name ,
183+ name = r .name ,
184+ url = r .html_url ,
185+ default_branch = default_branch ,
186+ owner = owner ,
187+ )
188188 )
189+
189190 return result
190191
191192 def get_comments (self , repo , obj ) -> list [Comment ]:
@@ -246,6 +247,34 @@ def get_invites(self, repo: Repository) -> list[Invite]:
246247 def get_rate_limiting (self ) -> tuple [int , int ]:
247248 return self .client .rate_limiting
248249
250+ def get_workflow_runs (self , repo ) -> list [WorkflowRun ]:
251+ try :
252+ runs = self .client .get_repo (repo ._id ).get_workflow_runs ()
253+
254+ return [
255+ WorkflowRun (
256+ display_title = r .display_title ,
257+ event = r .event ,
258+ head_branch = r .head_branch ,
259+ head_sha = r .head_sha ,
260+ name = r .name ,
261+ path = r .path ,
262+ created_at = r .created_at ,
263+ run_started_at = r .run_started_at ,
264+ updated_at = r .updated_at ,
265+ conclusion = r .conclusion ,
266+ status = r .status ,
267+ url = r .url ,
268+ )
269+ for r in runs
270+ ]
271+
272+ except Exception as e :
273+ logging .error (
274+ f"Failed to get workflow runs from GitHub for repo { repo .name } : { e } "
275+ )
276+ return []
277+
249278
250279# Точка входа для тестирования
251280if __name__ == "__main__" :
0 commit comments