mirror of
https://github.com/adnanh/webhook.git
synced 2026-07-27 01:29:16 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f83af97138 | |||
| 5a96a5721a |
@@ -49,6 +49,7 @@ type Hook struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ExecuteCommand string `json:"execute-command"`
|
ExecuteCommand string `json:"execute-command"`
|
||||||
CommandWorkingDirectory string `json:"command-working-directory"`
|
CommandWorkingDirectory string `json:"command-working-directory"`
|
||||||
|
ResponseMessage string `json:"response-message"`
|
||||||
PassArgumentsToCommand []Argument `json:"pass-arguments-to-command"`
|
PassArgumentsToCommand []Argument `json:"pass-arguments-to-command"`
|
||||||
TriggerRule *Rules `json:"trigger-rule"`
|
TriggerRule *Rules `json:"trigger-rule"`
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-12
@@ -22,18 +22,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "2.2.0"
|
version = "2.2.2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ip = flag.String("ip", "", "ip the webhook should serve hooks on")
|
ip = flag.String("ip", "", "ip the webhook should serve hooks on")
|
||||||
port = flag.Int("port", 9000, "port the webhook should serve hooks on")
|
port = flag.Int("port", 9000, "port the webhook should serve hooks on")
|
||||||
verbose = flag.Bool("verbose", false, "show verbose output")
|
verbose = flag.Bool("verbose", false, "show verbose output")
|
||||||
hotReload = flag.Bool("hotreload", false, "watch hooks file for changes and reload them automatically")
|
hotReload = flag.Bool("hotreload", false, "watch hooks file for changes and reload them automatically")
|
||||||
hooksFilePath = flag.String("hooks", "hooks.json", "path to the json file containing defined hooks the webhook should serve")
|
hooksFilePath = flag.String("hooks", "hooks.json", "path to the json file containing defined hooks the webhook should serve")
|
||||||
secure = flag.Bool("secure", false, "use HTTPS instead of HTTP")
|
hooksURLPrefix = flag.String("urlprefix", "hooks", "url prefix to use for served hooks (protocol://yourserver:port/PREFIX/:hook-id)")
|
||||||
cert = flag.String("cert", "cert.pem", "path to the HTTPS certificate pem file")
|
secure = flag.Bool("secure", false, "use HTTPS instead of HTTP")
|
||||||
key = flag.String("key", "key.pem", "path to the HTTPS certificate private key pem file")
|
cert = flag.String("cert", "cert.pem", "path to the HTTPS certificate pem file")
|
||||||
|
key = flag.String("key", "key.pem", "path to the HTTPS certificate private key pem file")
|
||||||
|
|
||||||
watcher *fsnotify.Watcher
|
watcher *fsnotify.Watcher
|
||||||
|
|
||||||
@@ -106,7 +107,16 @@ func main() {
|
|||||||
n := negroni.New(negroniRecovery, negroniLogger)
|
n := negroni.New(negroniRecovery, negroniLogger)
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.HandleFunc("/hooks/{id}", hookHandler)
|
|
||||||
|
var hooksURL string
|
||||||
|
|
||||||
|
if *hooksURLPrefix == "" {
|
||||||
|
hooksURL = "/{id}"
|
||||||
|
} else {
|
||||||
|
hooksURL = "/" + *hooksURLPrefix + "/{id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
router.HandleFunc(hooksURL, hookHandler)
|
||||||
|
|
||||||
n.UseHandler(router)
|
n.UseHandler(router)
|
||||||
|
|
||||||
@@ -165,9 +175,10 @@ func hookHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// handle hook
|
// handle hook
|
||||||
go handleHook(hook, &headers, &query, &payload, &body)
|
go handleHook(hook, &headers, &query, &payload, &body)
|
||||||
|
|
||||||
// say thanks
|
// send the hook defined response message
|
||||||
fmt.Fprintf(w, "Thanks.")
|
fmt.Fprintf(w, hook.ResponseMessage)
|
||||||
} else {
|
} else {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
fmt.Fprintf(w, "Hook not found.")
|
fmt.Fprintf(w, "Hook not found.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user