Skip to content

Commit

Permalink
Inform requesters that they likely forgot to add a path if they hit `…
Browse files Browse the repository at this point in the history
…https://<webhook_url>/` (#29)
  • Loading branch information
anoadragon453 authored Nov 23, 2022
1 parent b2dab92 commit f6343be
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import logging
from typing import Dict

from flask import Flask
from flask import Flask, request
from github import Github
from github.Repository import Repository
from github_webhook import Webhook
Expand All @@ -40,7 +40,7 @@ def __init__(
self.repo = repo
self.command_handler = CommandHandler(config, store, repo)

# Start a flash webserver
# Start a flask webserver
self.app = Flask(__name__)

webhook = Webhook(
Expand All @@ -49,9 +49,15 @@ def __init__(
secret=self.config.webhook_secret,
)

@self.app.route("/")
def hello_world():
return "Hello, world!"
@self.app.route("/<path:path>", methods=["GET", "POST"])
def invalid_path_route(path):
"""Respond to a request on an unrecognised HTTP method + path combination."""
# We never expect a GET.
if request.method != "POST":
return "This application only responds to POST requests", 405

# The requester used a POST, but didn't use the configured webhook URL.
return "Did you forget to use the configured webhook path? :)", 404

@webhook.hook("issue_comment")
def on_issue_comment(data):
Expand Down

0 comments on commit f6343be

Please sign in to comment.