Githubevents
GitHub webhook events toolset for Go :rocket:
Install / Use
/learn @cbrgm/GithubeventsREADME
githubevents
<img src=".img/gopher.png" width="150px" align="right" />GitHub webhook events toolset for Go
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.Contexthas 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

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
-
***[ping](https://docs.github.com/en/
Related Skills
apple-reminders
348.0kManage Apple Reminders via remindctl CLI (list, add, edit, complete, delete). Supports lists, date filters, and JSON/plain output.
gh-issues
348.0kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
node-connect
348.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
oracle
348.0kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
