-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3f05657
Showing
36 changed files
with
2,949 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: daily | ||
- package-ecosystem: gomod | ||
directory: / | ||
schedule: | ||
interval: daily |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Go Static Analysis | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
golangci: | ||
name: nilaway | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: install nilaway | ||
run: go install go.uber.org/nilaway/cmd/nilaway@latest | ||
|
||
- name: nilaway | ||
run: ~/go/bin/nilaway ./... | ||
continue-on-error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Go Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Go Test | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
env: | ||
GOPROXY: "https://proxy.golang.org" | ||
|
||
jobs: | ||
test: | ||
name: "go test" | ||
strategy: | ||
matrix: | ||
go-version: [ 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x ] | ||
platform: [ ubuntu-latest, windows-latest, macos-latest ] | ||
runs-on: ${{ matrix.platform }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- run: go version | ||
|
||
- name: Run tests | ||
run: go test ./... -v -covermode=atomic -race -coverprofile=coverage.txt | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
vendor/ | ||
.idea | ||
_example | ||
.todo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
linters: | ||
disable-all: true | ||
|
||
enable: | ||
- bodyclose | ||
- dogsled | ||
- durationcheck | ||
- errcheck | ||
- exportloopref | ||
- govet | ||
- gosimple | ||
- gofmt | ||
- gofumpt | ||
- goconst | ||
- goimports | ||
- mnd | ||
- gocyclo | ||
- ineffassign | ||
- lll | ||
- prealloc | ||
- revive | ||
- staticcheck | ||
- typecheck | ||
- unused | ||
- whitespace | ||
- wastedassign | ||
- unconvert | ||
- misspell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 flc1125 (https://github.com/flc1125, https://flc.io) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.PHONY: init | ||
init: | ||
go install mvdan.cc/gofumpt@latest | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
|
||
.PHONY: lint | ||
lint: | ||
golangci-lint run | ||
@echo "✅ Linting completed" | ||
|
||
.PHONY: fix | ||
fix: | ||
golangci-lint run --fix | ||
@echo "✅ Lint fixing completed" | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... -race | ||
@echo "✅ Testing completed" | ||
|
||
.PHONY: fmt | ||
fmt: | ||
gofmt -w -e "vendor" . | ||
@echo "✅ Formatting completed" | ||
|
||
.PHONY: fumpt | ||
fumpt: | ||
gofumpt -w -e "vendor" . | ||
@echo "✅ Formatting completed" | ||
|
||
.PHONY: nilaway-install | ||
nilaway-install: | ||
go install go.uber.org/nilaway/cmd/nilaway@latest | ||
|
||
.PHONY: nilaway | ||
nilaway: | ||
nilaway ./... | ||
@echo "✅ Nilaway completed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# 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 https://github.com/flc1125/go-gitlab-webhook | ||
``` | ||
|
||
## 💻 Usage | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/xanzy/go-gitlab" | ||
|
||
"github.com/flc1125/gitlabwebhook" | ||
) | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
coverage: | ||
require_ci_to_pass: true | ||
|
||
status: | ||
project: | ||
default: | ||
target: 90% | ||
threshold: 50% | ||
|
||
patch: | ||
default: | ||
target: 90% | ||
threshold: 80% |
Oops, something went wrong.