Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Show parameters on index access
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Jul 2, 2018
1 parent 9253bda commit 73f1931
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
12 changes: 8 additions & 4 deletions server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
// WebhookHandler handles requests from JIRA wehbook.
type WebhookHandler struct{}

type requestParams struct {
type webhookParams struct {
webhook string
username string
icon string
dialect message.Dialect
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 == "" {
Expand All @@ -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)
Expand Down

0 comments on commit 73f1931

Please sign in to comment.