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
Comments
  • chore(deps): bump actions/setup-go from 2 to 3

    chore(deps): bump actions/setup-go from 2 to 3

    Bumps actions/setup-go from 2 to 3.

    Release notes

    Sourced from actions/setup-go's releases.

    v3.0.0

    What's Changed

    Breaking Changes

    With the update to Node 16, all scripts will now be run with Node 16 rather than Node 12.

    This new major release removes the stable input, so there is no need to specify additional input to use pre-release versions. This release also corrects the pre-release versions syntax to satisfy the SemVer notation (1.18.0-beta1 -> 1.18.0-beta.1, 1.18.0-rc1 -> 1.18.0-rc.1).

    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
        with:
          go-version: '1.18.0-rc.1' 
      - run: go version
    

    Add check-latest input

    In scope of this release we add the check-latest input. If check-latest is set to true, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a Go version will then be downloaded from go-versions repository. By default check-latest is set to false. Example of usage:

    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
        with:
          go-version: '1.16'
          check-latest: true
      - run: go version
    

    Moreover, we updated @actions/core from 1.2.6 to 1.6.0

    v2.1.5

    In scope of this release we updated matchers.json to improve the problem matcher pattern. For more information please refer to this pull request

    v2.1.4

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/setup-go/compare/v2.1.3...v2.1.4

    v2.1.3

    • Updated communication with runner to use environment files rather then workflow commands

    v2.1.2

    This release includes vendored licenses for this action's npm dependencies.

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • chore(deps): bump golangci/golangci-lint-action from 3.2.0 to 3.3.0

    chore(deps): bump golangci/golangci-lint-action from 3.2.0 to 3.3.0

    Bumps golangci/golangci-lint-action from 3.2.0 to 3.3.0.

    Commits
    • 07db538 build(deps): bump @​actions/cache from 3.0.4 to 3.0.5 (#586)
    • 328c000 build(deps-dev): bump @​typescript-eslint/eslint-plugin from 5.39.0 to 5.40.0 ...
    • 3a79f8d build(deps-dev): bump @​typescript-eslint/parser from 5.39.0 to 5.40.0 (#584)
    • 43c645b build(deps-dev): bump eslint from 8.24.0 to 8.25.0 (#582)
    • 88e5fc6 build(deps-dev): bump @​typescript-eslint/eslint-plugin from 5.38.1 to 5.39.0 ...
    • 6191de5 build(deps-dev): bump @​typescript-eslint/parser from 5.38.1 to 5.39.0 (#580)
    • 5423639 build(deps): bump @​actions/core from 1.9.1 to 1.10.0 (#578)
    • c225631 build(deps): bump @​actions/github from 5.1.0 to 5.1.1 (#576)
    • b81d829 build(deps-dev): bump typescript from 4.8.3 to 4.8.4 (#577)
    • 5b682fd build(deps-dev): bump @​typescript-eslint/parser from 5.38.0 to 5.38.1 (#575)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • chore(deps): bump github.com/google/go-github/v47 from 47.0.0 to 47.1.0

    chore(deps): bump github.com/google/go-github/v47 from 47.0.0 to 47.1.0

    Bumps github.com/google/go-github/v47 from 47.0.0 to 47.1.0.

    Release notes

    Sourced from github.com/google/go-github/v47's releases.

    v47.1.0

    This minor release includes these changes:

    • Update scrape dependency to v47 (#2442)
    • Additional options name, default_branch_only for create a fork (#2448)
    • List Secret Scan Alerts with index-based pagination (#2446)
    • Add alphanumeric param to AutolinkOptions (#2450)
    • Remove GenerateReleaseNotes from RepositoriesService.EditRelease (#2445)
    • Add org permissions to InstallationPermissions (#2452)
    • Escape special characters in ref name for update ref (#2454)
    • Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#2457)
    • Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 in /scrape (#2458)
    • Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 in /update-urls (#2459)
    • Fix unhandled error in actions_artifacts.go (#2460)
    • Add explicit error return (#2469)
    • Add org struct fields (#2471)
    • Always send 'checks' field when creating branch protection (#2468)
    Commits
    • 23a2636 Always send 'checks' field when creating branch protection (#2468)
    • 642c343 Add org struct fields (#2471)
    • 30d1431 Add explicit error return (#2469)
    • d611561 Fix unhandled error in actions_artifacts.go (#2460)
    • e2f7379 Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 in /update-urls (#2459)
    • af7f4ae Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 in /scrape (#2458)
    • f452c62 Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#2457)
    • ae774d0 Escape special characters in ref name for update ref (#2454)
    • 52cc49e Add org permissions to InstallationPermissions (#2452)
    • e8cac35 Remove GenerateReleaseNotes from RepositoriesService.EditRelease (#2445)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • chore(deps): bump github.com/google/go-github/v45 from 45.1.0 to 45.2.0

    chore(deps): bump github.com/google/go-github/v45 from 45.1.0 to 45.2.0

    Bumps github.com/google/go-github/v45 from 45.1.0 to 45.2.0.

    Release notes

    Sourced from github.com/google/go-github/v45's releases.

    v45.2.0

    This minor release includes these changes:

    • Add Actor field to WorkflowRun (#2381)
    • Bump github.com/google/go-github/v45 from 45.0.0 to 45.1.0 in /scrape (#2382)
    • docs fix: correct a comment (#2383)
    • Add missing common event fields (#2384)
    • Add RoleName field to User struct (#2386)
    • Add support for repo setting use_squash_pr_title_as_default (#2390)
    • Add MembersCanForkPrivateRepositories field to Organization struct (#2389)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • chore(deps): bump golangci/golangci-lint-action from 3.1.0 to 3.2.0

    chore(deps): bump golangci/golangci-lint-action from 3.1.0 to 3.2.0

    Bumps golangci/golangci-lint-action from 3.1.0 to 3.2.0.

    Release notes

    Sourced from golangci/golangci-lint-action's releases.

    v3.2.0

    What's Changed

    misc

    dependencies

    New Contributors

    ... (truncated)

    Commits
    • 537aa19 Expire cache periodically to avoid unbounded size (#466)
    • f70e52d build(deps): bump @​actions/core from 1.6.0 to 1.8.0 (#468)
    • a304692 build(deps-dev): bump @​typescript-eslint/eslint-plugin (#469)
    • eeca7c5 build(deps-dev): bump eslint from 8.14.0 to 8.15.0 (#467)
    • dfbcd2a build(deps): bump github/codeql-action from 1 to 2 (#459)
    • 4421331 build(deps-dev): bump @​typescript-eslint/parser from 5.20.0 to 5.22.0 (#464)
    • 5e6c1bb build(deps-dev): bump typescript from 4.6.3 to 4.6.4 (#461)
    • 44eba43 build(deps-dev): bump @​typescript-eslint/eslint-plugin (#460)
    • 358a5e3 build(deps-dev): bump @​typescript-eslint/eslint-plugin (#457)
    • b9c65a5 build(deps-dev): bump @​typescript-eslint/parser from 5.19.0 to 5.20.0 (#455)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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

Oct 15, 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

Aug 26, 2022
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

Nov 29, 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

Oct 15, 2022
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

Nov 24, 2022
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

Nov 24, 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

Dec 1, 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

Nov 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

Oct 20, 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

Nov 25, 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

Nov 29, 2022