Skip to content
develop
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

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)
}

About

Go library that makes working with Github webhooks delivered with AWS APIGateway easier.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages