Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flc1125/go-gitlab-webhook
🚀 A lightweight Gitlab webhook dispatcher for efficient event handling
https://github.com/flc1125/go-gitlab-webhook
dispatcher event gitlab golang webhook
Last synced: 4 months ago
JSON representation
🚀 A lightweight Gitlab webhook dispatcher for efficient event handling
- Host: GitHub
- URL: https://github.com/flc1125/go-gitlab-webhook
- Owner: flc1125
- License: mit
- Created: 2024-08-19T11:48:50.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-09-10T00:30:29.000Z (5 months ago)
- Last Synced: 2024-09-30T03:03:07.104Z (4 months ago)
- Topics: dispatcher, event, gitlab, golang, webhook
- Language: Go
- Homepage: https://github.com/flc1125/go-gitlab-webhook
- Size: 37.1 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gitlab Webhook Dispatcher 🚀
![Supported Go Versions](https://img.shields.io/badge/Go-%3E%3D1.18-blue)
[![Package Version](https://badgen.net/github/release/flc1125/go-gitlab-webhook/stable)](https://github.com/flc1125/go-gitlab-webhook/releases)
[![GoDoc](https://pkg.go.dev/badge/github.com/flc1125/go-gitlab-webhook)](https://pkg.go.dev/github.com/flc1125/go-gitlab-webhook)
[![codecov](https://codecov.io/gh/flc1125/go-gitlab-webhook/graph/badge.svg?token=QPTHZ5L9GT)](https://codecov.io/gh/flc1125/go-gitlab-webhook)
[![Go Report Card](https://goreportcard.com/badge/github.com/flc1125/go-gitlab-webhook)](https://goreportcard.com/report/github.com/flc1125/go-gitlab-webhook)
[![lint](https://github.com/flc1125/go-gitlab-webhook/actions/workflows/lint.yml/badge.svg)](https://github.com/flc1125/go-gitlab-webhook/actions/workflows/lint.yml)
[![tests](https://github.com/flc1125/go-gitlab-webhook/actions/workflows/test.yml/badge.svg)](https://github.com/flc1125/go-gitlab-webhook/actions/workflows/test.yml)
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)This is a simple webhook dispatcher for Gitlab. It listens for incoming webhooks and dispatches them to the appropriate handler.
## ✨ Features
- 📋 Very convenient registration of listeners
- 🔄 A single listener can implement multiple different webhook functions
- âš¡ Support asynchronous and efficient processing
- 🚀 Multiple dispatch methods## 📦 Installation
```shell
go get github.com/flc1125/go-gitlab-webhook
```## 💻 Usage
```go
package mainimport (
"context"
"net/http""github.com/xanzy/go-gitlab"
"github.com/flc1125/go-gitlab-webhook"
)var (
_ gitlabwebhook.BuildListener = (*testBuildListener)(nil)
_ gitlabwebhook.CommitCommentListener = (*testCommitCommentListener)(nil)
_ gitlabwebhook.BuildListener = (*testBuildAndCommitCommentListener)(nil)
_ gitlabwebhook.CommitCommentListener = (*testBuildAndCommitCommentListener)(nil)
)type testBuildListener struct{}
func (l *testBuildListener) OnBuild(ctx context.Context, event *gitlab.BuildEvent) error {
// do something
return nil
}type testCommitCommentListener struct{}
func (l *testCommitCommentListener) OnCommitComment(ctx context.Context, event *gitlab.CommitCommentEvent) error {
// do something
return nil
}type testBuildAndCommitCommentListener struct{}
func (l *testBuildAndCommitCommentListener) OnBuild(ctx context.Context, event *gitlab.BuildEvent) error {
// do something
return nil
}func (l *testBuildAndCommitCommentListener) OnCommitComment(ctx context.Context, event *gitlab.CommitCommentEvent) error {
// do something
return nil
}func main() {
dispatcher := gitlabwebhook.NewDispatcher(
gitlabwebhook.RegisterListeners(
&testBuildListener{},
&testCommitCommentListener{},
&testBuildAndCommitCommentListener{},
),
)dispatcher.RegisterListeners(
&testBuildListener{},
&testCommitCommentListener{},
&testBuildAndCommitCommentListener{},
)http.Handle("/webhook", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := dispatcher.DispatchRequest(r,
gitlabwebhook.DispatchRequestWithContext(context.Background()), // custom context
); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}w.WriteHeader(http.StatusNoContent)
}))if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
```## 📜 License
MIT License. See [LICENSE](LICENSE) for the full license text.
## 💖 Thanks
- [xanzy/go-gitlab](https://github.com/xanzy/go-gitlab): Go library for accessing the GitLab API
- [stretchr/testify](github.com/stretchr/testify): A toolkit with common assertions and mocks that plays nicely with the standard library