githubhook

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2016 License: MIT Imports: 8 Imported by: 9

README

githubhook

Golang parser for github webhooks. Not a server, though it could be integrated with one.

Installation

$ go get gopkg.in/rjz/githubhook.v0

Usage

Given an incoming *http.Request representing a webhook signed with a secret, use githubhook to validate and parse its content:

secret := []byte("don't tell!")
hook, err := githubhook.Parse(secret, req)

Plays nicely with the google/go-github client!

evt := github.PullRequestEvent{}
if err := json.Unmarshal(hook.Payload, &evt); err != nil {
  fmt.Println("Invalid JSON?", err)
}

Documentation

Overview

Package githubhook implements handling and verification of github webhooks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {

	// Id specifies the Id of a github webhook request.
	//
	// Id is extracted from the inbound request's `X-Github-Delivery` header.
	Id string

	// Event specifies the event name of a github webhook request.
	//
	// Event is extracted from the inbound request's `X-GitHub-Event` header.
	// See: https://developer.github.com/webhooks/#events
	Event string

	// Signature specifies the signature of a github webhook request.
	//
	// Signature is extracted from the inbound request's `X-Hub-Signature` header.
	Signature string

	// Payload contains the raw contents of the webhook request.
	//
	// Payload is extracted from the JSON-formatted body of the inbound request.
	Payload []byte
}

Hook is an inbound github webhook

func New

func New(req *http.Request) (hook *Hook, err error)

New reads a Hook from an incoming HTTP Request.

func Parse

func Parse(secret []byte, req *http.Request) (hook *Hook, err error)

Parse reads and verifies the hook in an inbound request.

func (*Hook) Extract

func (h *Hook) Extract(dst interface{}) error

Extract unmarshals Payload into a destination interface.

func (*Hook) SignedBy

func (h *Hook) SignedBy(secret []byte) bool

SignedBy checks that the provided secret matches the hook Signature

Implements validation described in github's documentation: https://developer.github.com/webhooks/securing/

Jump to

Keyboard shortcuts

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