Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions gh_org_mgr/_gh_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
GithubIntegration,
UnknownObjectException,
)
from github.GithubException import BadCredentialsException
from github.NamedUser import NamedUser
from github.Organization import Organization
from github.Repository import Repository
from github.Team import Team
from jwt.exceptions import InvalidKeyError

from ._gh_api import get_github_secrets_from_env, run_graphql_query

Expand Down Expand Up @@ -65,6 +67,7 @@ def _sluggify_teamname(self, team: str) -> str:
# supported, or multiple spaces etc.
return team.replace(" ", "-")

# amazonq-ignore-next-line
def login(
self, orgname: str, token: str = "", app_id: str | int = "", app_private_key: str = ""
) -> None:
Expand All @@ -81,7 +84,11 @@ def login(
logging.debug("Logging in via app %s", self.gh_app_id)
auth = Auth.AppAuth(app_id=self.gh_app_id, private_key=self.gh_app_private_key)
app = GithubIntegration(auth=auth)
installation = app.get_org_installation(org=orgname)
try:
installation = app.get_org_installation(org=orgname)
except InvalidKeyError:
logging.critical("Invalid private key provided for GitHub App")
sys.exit(1)
self.gh = installation.get_github_for_installation()
logging.debug("Logged in via app installation %s", installation.id)

Expand All @@ -90,7 +97,11 @@ def login(
elif self.gh_token:
logging.debug("Logging in as user with PAT")
self.gh = Github(auth=Auth.Token(self.gh_token))
logging.debug("Logged in as %s", self.gh.get_user().login)
try:
logging.debug("Logged in as %s", self.gh.get_user().login)
except BadCredentialsException:
logging.critical("Invalid GitHub token provided")
sys.exit(1)
else:
logging.error("No GitHub token or App ID+private key provided")
sys.exit(1)
Expand Down