hookserve

package module
v0.0.0-...-4ddf89a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2018 License: BSD-3-Clause Imports: 0 Imported by: 0

README

HookServe

http://godoc.org/github.com/chappjc/hookserve/hookserve

HookServe is a small golang utility for receiving github webhooks, originally by phayes. It's easy to use, flexible, and provides strong security though GitHub's HMAC webhook verification scheme.

server := hookserve.NewServer()
server.Port = 8888
server.Secret = "supersecretcode"
server.GoListenAndServe()

// Every time the server receives a webhook event, print the results
for event := range server.Events {
    fmt.Println(event.Owner + " " + event.Repo + " " + event.Branch + " " + event.Commit)
}

Command Line Utility

It also comes with a command-line utility that lets you pass webhook push events to other commands.

hookserve --port=8888 logger -t PushEvent #log github webhook push event to the system log (/var/log/message) via the logger command

Example output in response to a push event:

web hook received: event type push on chappjc/webfiles, branch master, [90b7cc2e3]
Launching command: /home/ubuntu/go/src/github.com/chappjc/webfiles/cmd/webfiles/relaunch.sh
Building From Source

First install Go, then:

go get -u github.com/chappjc/hookserve/util/hookserve

GitHub Webhooks

Setting up webhooks on GitHub is easy. Navigate to github.com/<name>/<repo>/settings/hooks and create a new webhook. Be sure to use application/json as the content type, and don't forget the /postreceive part of the Payload URL. Setting up your webhook should look something like this:

Configuring webhooks in GitHub

Documentation

Overview

HookServe is a small golang utility for receiving github webhooks. It's easy to use, flexible, and provides strong security though GitHub's HMAC webhook verification scheme.

server := hookserve.NewServer()
server.Port = 8888
server.Secret = "supersecretcode"
server.GoListenAndServe()

for {
    select {
    case event := <-server.Events:
        fmt.Println(event.Owner + " " + event.Repo + " " + event.Branch + " " + event.Commit)
    default:
        time.Sleep(100)
    }
}

Command Line Utility

It also comes with a command-line utility that lets you pass webhook push events to other commands.

$ hookserve --port=8888 logger -t PushEvent #log github webhook push event to the system log (/var/log/message) via the logger command

Settings up GitHub Webhooks

Setting up webhooks on github is easy. Navigate to `github.com/<name>/<repo>/settings/hooks` and create a new webhook.

Directories

Path Synopsis
HookServe is a small golang utility for receiving github webhooks.
HookServe is a small golang utility for receiving github webhooks.
util

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL