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

Overview

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.

You might also like...
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

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

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

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

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

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

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

A high performance online bookstore system.

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

🔑 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

Comments
Releases(v1.4.0)
  • v1.4.0(Aug 30, 2022)

    This release is backward compatible to v1.3.0. There are no API changes.

    What's Changed

    • deps: dependabot batch, update to go-github v47 by @cbrgm in https://github.com/cbrgm/githubevents/pull/22

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.3.0...v1.4.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Aug 30, 2022)

    This release is backward compatible to v1.2.0. There are no API changes.

    What's Changed

    • docs: update readme by @cbrgm in https://github.com/cbrgm/githubevents/pull/16
    • docs: update readme by @cbrgm in https://github.com/cbrgm/githubevents/pull/17
    • chore(deps): bump golangci/golangci-lint-action from 3.1.0 to 3.2.0 by @dependabot in https://github.com/cbrgm/githubevents/pull/18
    • deps: update to google/go-github v45.1.0 by @cbrgm in https://github.com/cbrgm/githubevents/pull/19
    • chore(deps): bump github.com/google/go-github/v45 from 45.1.0 to 45.2.0 by @dependabot in https://github.com/cbrgm/githubevents/pull/20
    • deps: dependabot batch, update to go-github v46 by @cbrgm in https://github.com/cbrgm/githubevents/pull/21

    New Contributors

    • @dependabot made their first contribution in https://github.com/cbrgm/githubevents/pull/18

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(May 27, 2022)

    This release is backward compatible to v1.1.21. There are no API changes.

    What's Changed

    • deps: add support for google/go-github v45.0.0 by @cbrgm in https://github.com/cbrgm/githubevents/pull/15

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.1.21...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.21(May 14, 2022)

    What's Changed

    • deps: update golang.org/x/crypto by @cbrgm in https://github.com/cbrgm/githubevents/pull/13
    • deps: bump google/go-github from v44.0.0 to v44.1.0 by @cbrgm in https://github.com/cbrgm/githubevents/pull/14

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.1.2...v1.1.21

    Source code(tar.gz)
    Source code(zip)
  • v1.1.2(May 3, 2022)

    This release is backward compatible to v1.1.1. There are no API changes.

    What's Changed

    • deps: update dependencies by @cbrgm in https://github.com/cbrgm/githubevents/pull/11
    • Update to github.com/google/go-github/v44 by @cbrgm in https://github.com/cbrgm/githubevents/pull/12

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.1.1...v1.1.2

    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Apr 29, 2022)

    What's Changed

    • tests: increase test coverage, add unit tests by @cbrgm in https://github.com/cbrgm/githubevents/pull/9
    • fix(typo): fix RepositoryEventCreated name by @cbrgm in https://github.com/cbrgm/githubevents/pull/10

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.1.0...v1.1.1

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Apr 28, 2022)

    This release is backward compatible to v1.0.0. There are no API changes.

    This release changes the execution order of the waitgroups for Github webhook event callbacks. Callbacks that listen for all actions of an event are executed in parallel to those that listen for a specific event action. This saves execution time! Also there are now constants for each event action and the test coverage was increased!

    What's Changed

    • refactor: execute On... and On...Any callbacks in the same waitgroup by @cbrgm in https://github.com/cbrgm/githubevents/pull/6
    • feat: introduce event action constants by @cbrgm in https://github.com/cbrgm/githubevents/pull/6

    Full Changelog: https://github.com/cbrgm/githubevents/compare/v1.0.0...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 24, 2022)

Owner
Christian Bargmann
DevOps Engineer @moia-dev. I code things with my bare hands!
Christian Bargmann
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

Opstree Container Kit 112 Aug 25, 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

Xabier Larrakoetxea Gallego 8 Aug 26, 2022
Tcpdump-webhook - Toy Sidecar Injection with Mutating Webhook

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

Alp Kahvecioglu 2 Feb 8, 2022
Webhook-server - Webhook Server for KubeDB resources

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

Kubernetes Database 1 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

Philips Labs 2 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

Marco Lehmann 2 Feb 27, 2022
: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

Roger Welin 616 Sep 21, 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

Egor 3 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.

Ken’ichiro Oyama 1 Feb 6, 2022
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

Vanu 630 Sep 22, 2022