SkillAgentSearch skills...

Githubevents

GitHub webhook events toolset for Go :rocket:

Install / Use

/learn @cbrgm/Githubevents
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

githubevents

<img src=".img/gopher.png" width="150px" align="right" />

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.


GitHub Events V2 Released - Breaking Changes

V2 of githubevents has been released and introduces breaking changes that require refactoring to upgrade:

  • The import path has changed and is now: github.com/cbrgm/githubevents/v2/githubevents
  • context.Context has been added as the first argument to callback functions. Existing callbacks must be updated to accommodate this change.

Please ensure you update your import statements and refactor callback function signatures accordingly.

Usage

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

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

package main

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

func main() {
    // create a new event handler
    handle := githubevents.New("secretkey")

    // add callbacks
    handle.OnIssueCommentCreated(
      func(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, deliveryID string, eventName string, event interface{}, err error) error {
		fmt.Printf("received error %s", err)
		// additional error handling ...
		return err
	},
)
// ...

Supported Webhooks Events

Related Skills

View on GitHub
GitHub Stars92
CategoryDevelopment
Updated5d ago
Forks7

Languages

Go Template

Security Score

100/100

Audited on Mar 30, 2026

No findings