1- from github import Github , GithubException , PullRequest
21from interface_wrapper import (
32 RepositoryFactory ,
43 Repository ,
54 Branch ,
5+ IRepositoryAPI
66)
77from time import sleep
88
99TIMEDELTA = 0.05
1010TIMEZONE = 'Europe/Moscow'
1111
1212
13- def login (token ):
14- client = Github (login_or_token = token )
15-
16- try :
17- client .get_user ().login
18- except GithubException as err :
19- print (f'Github: Connect: error { err .data } ' )
20- print ('Github: Connect: user could not be authenticated please try again.' )
21- exit (1 )
22- else :
23- return client
13+ def login (source , token , base_url ):
14+ client = RepositoryFactory .create_api (source , token , base_url )
15+ return client
2416
2517
2618def get_tokens_from_file (tokens_path : str ) -> list [str ]:
@@ -30,24 +22,22 @@ def get_tokens_from_file(tokens_path: str) -> list[str]:
3022 return tokens
3123
3224
33- class GithubClients :
34- def __init__ (self , tokens : list [str ]):
35- self .clients = self ._init_clients (tokens )
25+ class GitClients :
26+ def __init__ (self , source : str , tokens : list [str ], base_url : str | None = None ):
27+ self .clients = self ._init_clients (source , tokens , base_url )
3628 self .cur_client = None
3729
38- def _init_clients (self , tokens : list [str ]) -> list [dict ]:
39- clients = [{"client" : login (token ), "token" : token } for token in tokens ]
40- for c in clients :
41- c ["api" ] = RepositoryFactory .create_api ("github" , c ["client" ])
30+ def _init_clients (self , source : str , tokens : list [str ], base_url : str | None ) -> list [dict ]:
31+ clients = [{"client" : login (source , token , base_url ), "token" : token } for token in tokens ]
4232
4333 return clients
4434
45- def get_next_client (self ) -> Github :
35+ def get_next_client (self ) -> IRepositoryAPI :
4636 client = None
4737 max_remaining_limit = - 1
4838
4939 for client_tmp in self .clients :
50- remaining_limit , limit = client_tmp ["client" ].rate_limiting
40+ remaining_limit , limit = client_tmp ["client" ].get_rate_limiting ()
5141
5242 # можно добавить вывод износа токена
5343 # можно дополнительно проверять на 403 и временно пропускать эти токены,
@@ -60,41 +50,36 @@ def get_next_client(self) -> Github:
6050 sleep (TIMEDELTA )
6151
6252 if client is None :
63- raise Exception ("No github- clients available" )
53+ raise Exception ("No git clients available" )
6454
6555 self .cur_client = client
6656 return client
6757
6858
69- def get_next_repo (clients : GithubClients , repositories ):
59+ def get_next_repo (clients : GitClients , repositories ):
7060 with open (repositories , 'r' ) as file :
7161 list_repos = [x for x in file .read ().split ('\n ' ) if x ]
7262 print (list_repos )
7363 for repo_name in list_repos :
7464 try :
7565 cur_client = clients .get_next_client ()
76- repo = cur_client ['client' ].get_repo (repo_name )
77- except GithubException as err :
78- print (f'Github: Connect: error { err . data } ' )
79- print (f'Github: Connect : failed to load repository "{ repo_name } "' )
66+ repo = cur_client ['client' ].get_repository (repo_name )
67+ except Exception as err :
68+ print (f'get_next_repo(): error { err } ' )
69+ print (f'get_next_repo() : failed to load repository "{ repo_name } "' )
8070 exit (1 )
8171 else :
8272 print (cur_client ['token' ])
83- yield Repository (
84- _id = repo .full_name ,
85- name = repo .name ,
86- url = repo .html_url ,
87- default_branch = Branch (name = repo .default_branch , last_commit = None ),
88- owner = cur_client ['api' ].get_user_data (repo .owner ),
89- ), cur_client ['token' ]
73+ yield repo , cur_client ['token' ]
9074
9175
92- def get_assignee_story (github_object ):
76+ def get_assignee_story (git_object ):
9377 # TODO
9478 return ""
79+
9580 assignee_result = ""
9681 events = (
97- github_object .get_issue_events ()
82+ git_object .get_issue_events ()
9883 if type (github_object ) is PullRequest .PullRequest
9984 else github_object .get_events ()
10085 )
0 commit comments