Skip to content

Commit f6343be

Browse files
Inform requesters that they likely forgot to add a path if they hit https://<webhook_url>/ (#29)
1 parent b2dab92 commit f6343be

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

webhook.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import logging
1616
from typing import Dict
1717

18-
from flask import Flask
18+
from flask import Flask, request
1919
from github import Github
2020
from github.Repository import Repository
2121
from github_webhook import Webhook
@@ -40,7 +40,7 @@ def __init__(
4040
self.repo = repo
4141
self.command_handler = CommandHandler(config, store, repo)
4242

43-
# Start a flash webserver
43+
# Start a flask webserver
4444
self.app = Flask(__name__)
4545

4646
webhook = Webhook(
@@ -49,9 +49,15 @@ def __init__(
4949
secret=self.config.webhook_secret,
5050
)
5151

52-
@self.app.route("/")
53-
def hello_world():
54-
return "Hello, world!"
52+
@self.app.route("/<path:path>", methods=["GET", "POST"])
53+
def invalid_path_route(path):
54+
"""Respond to a request on an unrecognised HTTP method + path combination."""
55+
# We never expect a GET.
56+
if request.method != "POST":
57+
return "This application only responds to POST requests", 405
58+
59+
# The requester used a POST, but didn't use the configured webhook URL.
60+
return "Did you forget to use the configured webhook path? :)", 404
5561

5662
@webhook.hook("issue_comment")
5763
def on_issue_comment(data):

0 commit comments

Comments
 (0)