Skip to content

Commit

Permalink
Update core.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kalisb authored Apr 5, 2024
1 parent cdb4bfd commit b7b51ad
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions githubapp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import distutils

from flask import abort, current_app, jsonify, request, _app_ctx_stack
from github3 import GitHub, GitHubEnterprise, login
from github3 import GitHub, GitHubEnterprise

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -36,7 +36,6 @@ def __init__(self, app=None):
def load_env(app):
app.config["GITHUBAPP_ID"] = int(os.environ["APP_ID"])
app.config["GITHUBAPP_SECRET"] = os.environ["WEBHOOK_SECRET"]
app.config["GITHUB_TOKEN"] = os.environ["TOKEN"]
if "GHE_HOST" in os.environ:
app.config["GITHUBAPP_URL"] = "https://{}".format(os.environ["GHE_HOST"])
app.config["VERIFY_SSL"] = bool(
Expand Down Expand Up @@ -97,11 +96,7 @@ def health_check():

@property
def id(self):
return current_app.config["GITHUBAPP_ID"]

@property
def token(self):
return current_app.config["GITHUB_TOKEN"]
return current_app.config["GITHUBAPP_ID"]

@property
def key(self):
Expand Down Expand Up @@ -182,9 +177,14 @@ def app_installation(self, installation_id=None):
"""
"""GitHub client authenticated as GitHub app installation"""
ctx = _app_ctx_stack.top
client = GitHub(token=self.token)
ctx.githubapp_installation = client
return ctx.githubapp_installation
if installation_id is None:
raise RuntimeError("Installation ID is not specified.")
if ctx is not None:
if not hasattr(ctx, "githubapp_installation"):
client = self.client
client.login_as_app_installation(self.key, self.id, installation_id)
ctx.githubapp_installation = client
return ctx.githubapp_installation

def on(self, event_action):
"""
Expand Down

0 comments on commit b7b51ad

Please sign in to comment.