From 73f19317316a7cac4fbce68479819c7668c8236d Mon Sep 17 00:00:00 2001 From: Hidetake Iwata Date: Mon, 2 Jul 2018 20:21:08 +0900 Subject: [PATCH] Show parameters on index access --- README.md | 7 ++++++- server/index.go | 7 ++++++- server/webhook.go | 12 ++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2439b91..fc840b4 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,11 @@ The server sends a message to the Slack channel on the following triggers: If the issue or comment has mentions (i.e. `@foo` or `[~foo]`), the server appends them to the title of message for Slack notification. +### Health check endpoint + +The server always returns 200 on `GET /healthz` for liveness probe and readiness probe. + + ## Contribution This is an open source software licensed under Apache License 2.0. @@ -71,7 +76,7 @@ Feel free to book your issues or pull requests. Start the server: ```sh -go build && ./jira-to-slack +go run main.go ``` ### E2E Test diff --git a/server/index.go b/server/index.go index b2d07be..1a7573d 100644 --- a/server/index.go +++ b/server/index.go @@ -9,5 +9,10 @@ import ( type IndexHandler struct{} func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "OK") + p, err := parseWebhookParams(r) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } else { + fmt.Fprintf(w, "Parameter=%+v", p) + } } diff --git a/server/webhook.go b/server/webhook.go index 03b6917..8db414e 100644 --- a/server/webhook.go +++ b/server/webhook.go @@ -15,7 +15,7 @@ import ( // WebhookHandler handles requests from JIRA wehbook. type WebhookHandler struct{} -type requestParams struct { +type webhookParams struct { webhook string username string icon string @@ -23,8 +23,8 @@ type requestParams struct { debug bool } -func parseRequestParams(r *http.Request) (*requestParams, error) { - p := &requestParams{} +func parseWebhookParams(r *http.Request) (*webhookParams, error) { + p := &webhookParams{} q := r.URL.Query() p.webhook = q.Get("webhook") if p.webhook == "" { @@ -43,15 +43,19 @@ func parseRequestParams(r *http.Request) (*requestParams, error) { return nil, fmt.Errorf("dialect must be slack (default) or mattermost") } switch q.Get("debug") { + case "": // default + case "0": // default case "1": p.debug = true + default: + return nil, fmt.Errorf("debug must be 0 (default) or 1") } return p, nil } func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - p, err := parseRequestParams(r) + p, err := parseWebhookParams(r) if err != nil { log.Print(err) http.Error(w, err.Error(), http.StatusBadRequest)