Skip to content
Go library that makes working with Github webhooks delivered with AWS APIGateway easier.
Go
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
vendor
.gitignore
LICENSE
README.md
event-fixture_test.go
ghhook.go
ghhook_test.go
github_events.go

README.md

ghhook

ghhook is a Go library that makes working with Github webhooks. This library assumes the wehooks are delivered via AWS APIGateway.

At its core you register an event name with a function that's run whenever webhook with that event name is received.

Example:

// Listen to "pull_request" event and return with 200 status.
ghhook.EventHandler(ghhook.PullRequestEvent, func(e interface{}) (*ghhook.Response, error) {
  pr, _ := e.(*github.PullRequestEvent)

  return &ghhook.Response{
    Body:       fmt.Sprintf("%s", *pr.Action),
    StatusCode: 200,
  }, nil
})

The input function has to be interface func(e interface{}) (*ghhook.Response, error). e maps to event struct that's specific to the webhook. ghhook uses the webhook event definitions from google/go-github. See here for list of all the available events and their respective mapping.

DefaultHandler

DefaultHandler is the start point which receives the webhook and runs the registered functions for the webhook. It's possible to use it as a lambda function out of the box.

lambda.Start(ghhook.DefaultHandler)

Full Lambda Example:

package main

import (
	"fmt"

	"github.com/WalkerAndCoBrandsInc/ghhook"
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/google/go-github/github"
)

func main() {
  ghhook.EventHandler(ghhook.PullRequestEvent, func(e interface{}) (*ghhook.Response, error) {
		pr, _ := e.(*github.PullRequestEvent)

		return &ghhook.Response{
			Body:       fmt.Sprintf("%s", *pr.Action),
			StatusCode: 200,
		}, nil
	})

  // important, this should be the last line since it blocks
  lambda.Start(ghhook.DefaultHandler)
}
You can’t perform that action at this time.