Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE THIS #26

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 7 additions & 9 deletions flask_githubapp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from flask import abort, current_app, jsonify, request, _app_ctx_stack
from github3 import GitHub, GitHubEnterprise


LOG = logging.getLogger(__name__)

STATUS_FUNC_CALLED = 'HIT'
Expand All @@ -22,6 +21,7 @@ class GitHubApp(object):
Keyword Arguments:
app {Flask object} -- App instance - created with Flask(__name__) (default: {None})
"""

def __init__(self, app=None):
self._hook_mappings = {}
if app is not None:
Expand Down Expand Up @@ -58,10 +58,10 @@ def init_app(self, app):
Path used for GitHub hook requests as a string.
Default: '/'
"""
required_settings = ['GITHUBAPP_ID', 'GITHUBAPP_KEY', 'GITHUBAPP_SECRET']
required_settings = ['GITHUBAPP_ID', 'GITHUBAPP_SECRET']
for setting in required_settings:
if not setting in app.config:
raise RuntimeError("Flask-GitHubApp requires the '%s' config var to be set" % setting)
if setting not in app.config:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was some PEP8 recommendation PyCharm made?

raise RuntimeError(f"Flask-GitHubApp requires the '{setting}' config var to be set")

app.add_url_rule(app.config.get('GITHUBAPP_ROUTE', '/'),
view_func=self._flask_view_func,
Expand Down Expand Up @@ -99,7 +99,7 @@ def client(self):
@property
def payload(self):
"""GitHub hook payload"""
if request and request.json and 'installation' in request.json:
if request and request.json:
return request.json

raise RuntimeError('Payload is only available in the context of a GitHub hook request')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hitting this runtime error... so I removed the installation check. YOLO

¯_(ツ)_/¯

Expand Down Expand Up @@ -151,6 +151,7 @@ def cruel_closer():
event_action {str} -- Name of the event and optional action (separated by a period), e.g. 'issues.opened' or
'pull_request'
"""

def decorator(f):
if event_action not in self._hook_mappings:
self._hook_mappings[event_action] = [f]
Expand All @@ -170,9 +171,6 @@ def _flask_view_func(self):
event = request.headers['X-GitHub-Event']
action = request.json.get('action')

if current_app.config['GITHUBAPP_SECRET'] is not False:
self._verify_webhook()

if event in self._hook_mappings:
functions_to_call += self._hook_mappings[event]

Expand All @@ -191,7 +189,7 @@ def _flask_view_func(self):
'calls': calls})

def _verify_webhook(self):
signature_header ='X-Hub-Signature-256'
signature_header = 'X-Hub-Signature-256'
signature_header_legacy = 'X-Hub-Signature'

if request.headers.get(signature_header):
Expand Down