1515 GithubIntegration ,
1616 UnknownObjectException ,
1717)
18+ from github .GithubException import BadCredentialsException
1819from github .NamedUser import NamedUser
1920from github .Organization import Organization
2021from github .Repository import Repository
2122from github .Team import Team
23+ from jwt .exceptions import InvalidKeyError
2224
2325from ._gh_api import get_github_secrets_from_env , run_graphql_query
2426
@@ -65,6 +67,7 @@ def _sluggify_teamname(self, team: str) -> str:
6567 # supported, or multiple spaces etc.
6668 return team .replace (" " , "-" )
6769
70+ # amazonq-ignore-next-line
6871 def login (
6972 self , orgname : str , token : str = "" , app_id : str | int = "" , app_private_key : str = ""
7073 ) -> None :
@@ -81,7 +84,11 @@ def login(
8184 logging .debug ("Logging in via app %s" , self .gh_app_id )
8285 auth = Auth .AppAuth (app_id = self .gh_app_id , private_key = self .gh_app_private_key )
8386 app = GithubIntegration (auth = auth )
84- installation = app .get_org_installation (org = orgname )
87+ try :
88+ installation = app .get_org_installation (org = orgname )
89+ except InvalidKeyError :
90+ logging .critical ("Invalid private key provided for GitHub App" )
91+ sys .exit (1 )
8592 self .gh = installation .get_github_for_installation ()
8693 logging .debug ("Logged in via app installation %s" , installation .id )
8794
@@ -90,7 +97,11 @@ def login(
9097 elif self .gh_token :
9198 logging .debug ("Logging in as user with PAT" )
9299 self .gh = Github (auth = Auth .Token (self .gh_token ))
93- logging .debug ("Logged in as %s" , self .gh .get_user ().login )
100+ try :
101+ logging .debug ("Logged in as %s" , self .gh .get_user ().login )
102+ except BadCredentialsException :
103+ logging .critical ("Invalid GitHub token provided" )
104+ sys .exit (1 )
94105 else :
95106 logging .error ("No GitHub token or App ID+private key provided" )
96107 sys .exit (1 )
0 commit comments