Skip to content

Commit e9c6935

Browse files
committed
improve app login, fetch access token for later graphql queries
1 parent c573563 commit e9c6935

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gh_org_mgr/_gh_org.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ def login(
7777

7878
# Decide how to login. If app set, prefer this
7979
if self.gh_app_id and self.gh_app_private_key:
80-
logging.debug("Logged in via app %s", self.gh_app_id)
80+
logging.debug("Logging in via app %s", self.gh_app_id)
8181
auth = Auth.AppAuth(app_id=self.gh_app_id, private_key=self.gh_app_private_key)
8282
app = GithubIntegration(auth=auth)
83-
installation = app.get_installations()[0]
83+
installation = app.get_org_installation(org=orgname)
8484
self.gh = installation.get_github_for_installation()
85+
logging.debug("Logged in via app installation %s", installation.id)
86+
87+
logging.debug("Getting access token for installation %s", installation.id)
88+
self.gh_token = app.get_access_token(installation_id=installation.id).token
8589
elif self.gh_token:
8690
logging.debug("Logging in as user with PAT")
8791
self.gh = Github(auth=Auth.Token(self.gh_token))
@@ -90,6 +94,7 @@ def login(
9094
logging.error("No GitHub token or App ID+private key provided")
9195
sys.exit(1)
9296

97+
logging.debug("Gathering data from organization '%s'", orgname)
9398
self.org = self.gh.get_organization(orgname)
9499
logging.debug("Gathered data from organization '%s' (%s)", self.org.login, self.org.name)
95100

0 commit comments

Comments
 (0)