High-performance GitHub webhook events toolset for Go :rocket:

githubevents

GitHub webhook events toolset for Go

release Go Report Card license license license GitHub stars

githubevents is a webhook events toolset for the Go programming language inspired by octokit/webhooks.js.

This library makes use of google/go-github and provides functionality to register callbacks for Github events and their actions, so that you can easily execute your own logic in response to webhook events.


Usage

import (
    "github.com/cbrgm/githubevents/githubevents"
)

Create a new githubevents.EventHandler, register callbacks and start a http server.

package main

import (
  "fmt"
  "github.com/cbrgm/githubevents/githubevents"
  "github.com/google/go-github/v45/github"
  "net/http"
)

func main() {
    // create a new event handler
    handle := githubevents.New("secretkey")
	
    // add callbacks
    handle.OnIssueCommentCreated(
      func(deliveryID string, eventName string, event *github.IssueCommentEvent) error {
          fmt.Printf("%s made a comment!", event.Sender.Login)
          return nil
      }, 
    ) 
	
    // add a http handleFunc
    http.HandleFunc("/hook", func(w http.ResponseWriter, r *http.Request) {
        err := handle.HandleEventRequest(r)
        if err != nil {
            fmt.Println("error")
        }
    })
	
    // start the server listening on port 8080
    if err := http.ListenAndServe(":8080", nil); err != nil {
        panic(err)
    }
}

For more usage examples, please have a look at the examples directory.

API

Please refer to pkg.go.dev for a full list of supported callback functions.

Constructor

To create a new githubevents.EventHandler use the following constructor:

handle := githubevents.New("secretkey")
// ...

secretkey is the GitHub Webhook secret token. If your webhook does not contain a secret token, you can set nil. This is intended for local development purposes only and all webhooks should ideally set up a secret token.

Callbacks

Functions to register callbacks follow a specific naming scheme. On... functions register one or more callbacks and add them to previously registered ones.

SetOn... functions also register callbacks, but override previously registered ones.

On...Any/SetOn...Any functions register callbacks that are executed on each action of an event (if the event has actions).

A full list of supported events for this Go module can be found under the section "Supported Webhooks Events". A full documentation including all functions to register callbacks can be found on pkg.go.dev.

Callback Execution Order

execution_order

Each callback in a registered group is executed in parallel. Each group blocks until all callbacks executed in parallel have returned, then returns the first non-nil error (if any) from them. If OnError callbacks have been set, they will be called when an error occurs. The order of execution is open for discussion, contributions are welcome!

OnBeforeAny

OnBeforeAny registers callbacks which are triggered before any event. Registered callbacks are executed in parallel in separate Goroutines.

handle := githubevents.New("secretkey")
handle.OnBeforeAny(
    func(deliveryID string, eventName string, event interface{}) error {
        fmt.Printf("%s event received!", eventName)
        // do something
        return nil
    },
)
// ...

OnAfterAny

OnAfterAny registers callbacks which are triggered after any event. Registered callbacks are executed in parallel in separate Goroutines.

handle := githubevents.New("secretkey")
handle.OnAfterAny(
    func(deliveryID string, eventName string, event interface{}) error {
        fmt.Printf("%s event received!", eventName)
        // do something
        return nil
    },
)
// ...

OnError

OnError registers callbacks which are triggered whenever an error occurs. These callbacks can be used for additional error handling, debugging or logging purposes. Registered callbacks are executed in parallel in separate Goroutines.

handle := githubevents.New("secretkey")
handle.OnError(
	func(deliveryID string, eventName string, event interface{}, err error) error {
		fmt.Printf("received error %s", err)
		// additional error handling ...
		return err
	}, 
)
// ...

Supported Webhooks Events

Local development

All Go code in githubevents is generated via the make target make generate (Go 1.18+ required). Changes must be done in gen/generate.go. To add new events, add a corresponding entry to gen/template_params.go.

To validate the generated go code run go run examples/simple-http-server and make changes to test your functions.

You can use services like ngrok to expose your local port 8080 to the world. Enter the public domain name as the webhook endpoint. You can install webhooks on an organization or on a specific repository. To set up a webhook, go to the settings page of your repository or organization. From there, click Webhooks, then Add webhook. Alternatively, you can choose to build and manage a webhook through the Webhooks API.

Compatibility

google/go-github cbrgm/githubevents
v45.x v1.2.x and above
v44.x v1.1.2x and below
v43.x v1.1.1x and below

Contributing & License

Feel free to submit changes! See the Contributing Guide. This project is open-source and is developed under the terms of the MIT License.

Owner
Christian Bargmann
DevOps Engineer @moia-dev. I code things with my bare hands!
Christian Bargmann
Similar Resources

topolvm operator provide kubernetes local storage which is light weight and high performance

Topolvm-Operator Topolvm-Operator is an open source cloud-native local storage orchestrator for Kubernetes, which bases on topolvm. Supported environm

Feb 8, 2022

An high performance and ops-free local storage solution for Kubernetes.

An high performance and ops-free local storage solution for Kubernetes.

Carina carina 是一个CSI插件,在Kubernetes集群中提供本地存储持久卷 项目状态:开发测试中 CSI Version: 1.3.0 Carina architecture 支持的环境 Kubernetes:1.20 1.19 1.18 Node OS:Linux Filesys

May 18, 2022

A batch scheduler of kubernetes for high performance workload, e.g. AI/ML, BigData, HPC

A batch scheduler of kubernetes for high performance workload, e.g. AI/ML, BigData, HPC

kube-batch kube-batch is a batch scheduler for Kubernetes, providing mechanisms for applications which would like to run batch jobs leveraging Kuberne

Jun 27, 2022

Carina: an high performance and ops-free local storage for kubernetes

Carina: an high performance and ops-free local storage for kubernetes

Carina English | 中文 Background Storage systems are complex! There are more and more kubernetes native storage systems nowadays and stateful applicatio

Jun 25, 2022

A high-performance Directed-Acyclic-Graph JIT in Go

A high-performance Directed-Acyclic-Graph JIT in Go

GAG - A Directed-Acyclic-Graph JIT in Go GAG is a library I created while developing https://isobot.io to experiment with different ways of implementi

Mar 16, 2022

A golang CTF competition platform with high-performance, security and low hardware requirements.

A golang CTF competition platform with high-performance, security and low hardware requirements.

CTFgo - CTF Platform written in Golang A golang CTF competition platform with high-performance, security and low hardware requirements. Live Demo • Di

Jun 12, 2022

StoneWork is a high-performance, all-(CNFs)-in-one network solution.

StoneWork, high-performance dataplane, modular control-plane solution StoneWork is used by PANTHEON.tech to integrate its CNFs on top of a single shar

Jun 21, 2022

A high performance online bookstore system.

HPOB 高性能网上书店 A high performance online bookstore system. Introduction 介绍 一个基于Gin、gorm、viper、zap等库的web服务器,实现了网上书店相关接口。 Summary 概要 使用go语言编写的,基于gin、gorm、

Apr 27, 2022

🔑 Kubernetes Authentication & Authorization WebHook Server

🔑 Kubernetes Authentication & Authorization WebHook Server

Guard Guard by AppsCode is a Kubernetes Webhook Authentication server. Using guard, you can log into your Kubernetes cluster using various auth provid

Jun 22, 2022
Comments
A k8s vault webhook is a Kubernetes webhook that can inject secrets into Kubernetes resources by connecting to multiple secret managers
A k8s vault webhook is a Kubernetes webhook that can inject secrets into Kubernetes resources by connecting to multiple secret managers

k8s-vault-webhook is a Kubernetes admission webhook which listen for the events related to Kubernetes resources for injecting secret directly from sec

Apr 28, 2022
Kubernetes webhook development (validating admission webhook) tutorial using kubewebhook

pod-exec-guard-kubewebhook-tutorial Introduction This is a tutorial that shows how to develop a Kubernetes admission webhook. To explain this, the tut

Dec 12, 2021
Tcpdump-webhook - Toy Sidecar Injection with Mutating Webhook

tcpdump-webhook A simple demonstration of Kubernetes Mutating Webhooks. Injects

Feb 8, 2022
Webhook-server - Webhook Server for KubeDB resources

webhook-server Webhook Server for KubeDB resources Installation To install KubeD

Feb 22, 2022
HSDP Metrics alerts webhook broker and CF events forwarder for Microsoft Teams

hsdp-events Microservice helper to translate HSDP Metrics webhooks to Microsoft Teams webhooks Configuration Environment Description EVENTS_TOKEN Rand

Mar 18, 2022
Kubernetes Admission Controller Demo: Validating Webhook for Namespace lifecycle events

Kubernetes Admission Controller Based on How to build a Kubernetes Webhook | Admission controllers Local Kuberbetes cluster # create kubernetes cluste

Feb 27, 2022
:rocket: Modern cross-platform HTTP load-testing tool written in Go
:rocket: Modern cross-platform HTTP load-testing tool written in Go

English | 中文 Cassowary is a modern HTTP/S, intuitive & cross-platform load testing tool built in Go for developers, testers and sysadmins. Cassowary d

Jun 24, 2022
(WIP) Extremely simple unixway GitHub webhook listener for push event

(WIP) puffy Puffy is an extremely simple unixway GitHub webhook listener and handler for push events Todo Add payload signature validation (WIP) Depen

Dec 30, 2021
Go-github-actions - `go-github-actions` is a package for developing GitHub Actions

go-github-actions go-github-actions is a package for developing GitHub Actions.

Feb 6, 2022
A Golang based high performance, scalable and distributed workflow framework
A Golang based high performance, scalable and distributed workflow framework

Go-Flow A Golang based high performance, scalable and distributed workflow framework It allows to programmatically author distributed workflow as Dire

Jun 28, 2022