Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PACKAGES = $(shell go list ./...)
GO := CGO_ENABLED=0 go
GOFUMPT_VERSION := v0.7.0
APIDIFF_VERSION := v0.0.0-20260811152304-ee035b5b010f
GOFUMPT ?= gofumpt

.PHONY: all
all: build
Expand All @@ -21,11 +22,8 @@ clean:
rm -rf ./bin/

.PHONY: format
format: go/fmt

.PHONY: go/fmt
go/fmt:
$(GO) fmt $(PACKAGES)
format:
$(GOFUMPT) -extra -w gen githubevents

.PHONY: test
test:
Expand All @@ -34,6 +32,7 @@ test:
.PHONY: generate
generate: build
./bin/githubhook-gen --output=githubevents
$(GOFUMPT) -extra -w githubevents

.PHONY: build
build: \
Expand Down
22 changes: 11 additions & 11 deletions gen/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package main

import (
"bytes"
gofmt "go/format"
"io"
"os"
"os/exec"
)

// format formats a template using gofmt.
// format formats a template using go/format.
func format(in io.Reader) (io.Reader, error) {
var out bytes.Buffer

gofmt := exec.Command("gofmt", "-s")
gofmt.Stdin = in
gofmt.Stdout = &out
gofmt.Stderr = os.Stderr
err := gofmt.Run()
return &out, err
src, err := io.ReadAll(in)
if err != nil {
return nil, err
}
out, err := gofmt.Source(src)
if err != nil {
return nil, err
}
return bytes.NewReader(out), nil
}
24 changes: 12 additions & 12 deletions gen/template_webhook_event.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func New(webhookSecret string) *EventHandler {
}

// EventHandleFunc represents a generic callback function which receives any event.
type EventHandleFunc func(ctx context.Context, deliveryID string, eventName string, event interface{}) error
type EventHandleFunc func(ctx context.Context, deliveryID string, eventName string, event any) error

// OnBeforeAny registers callbacks which are triggered before any event.
//
Expand All @@ -62,7 +62,7 @@ type EventHandleFunc func(ctx context.Context, deliveryID string, eventName stri
func (g *EventHandler) OnBeforeAny(callbacks ...EventHandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.onBeforeAny == nil {
Expand All @@ -80,7 +80,7 @@ func (g *EventHandler) OnBeforeAny(callbacks ...EventHandleFunc) {
func (g *EventHandler) SetOnBeforeAny(callbacks ...EventHandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.onBeforeAny == nil {
Expand All @@ -89,7 +89,7 @@ func (g *EventHandler) SetOnBeforeAny(callbacks ...EventHandleFunc) {
g.onBeforeAny[EventAnyAction] = callbacks
}

func (g *EventHandler) handleBeforeAny(ctx context.Context, deliveryID string, eventName string, event interface{}) error {
func (g *EventHandler) handleBeforeAny(ctx context.Context, deliveryID string, eventName string, event any) error {
if event == nil {
return fmt.Errorf("event was empty or nil")
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (g *EventHandler) handleBeforeAny(ctx context.Context, deliveryID string, e
func (g *EventHandler) OnAfterAny(callbacks ...EventHandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.onAfterAny == nil {
Expand All @@ -144,7 +144,7 @@ func (g *EventHandler) OnAfterAny(callbacks ...EventHandleFunc) {
func (g *EventHandler) SetOnAfterAny(callbacks ...EventHandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.onAfterAny == nil {
Expand All @@ -153,7 +153,7 @@ func (g *EventHandler) SetOnAfterAny(callbacks ...EventHandleFunc) {
g.onAfterAny[EventAnyAction] = callbacks
}

func (g *EventHandler) handleAfterAny(ctx context.Context, deliveryID string, eventName string, event interface{}) error {
func (g *EventHandler) handleAfterAny(ctx context.Context, deliveryID string, eventName string, event any) error {
if event == nil {
return fmt.Errorf("event was empty or nil")
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func (g *EventHandler) handleAfterAny(ctx context.Context, deliveryID string, ev

// ErrorEventHandleFunc represents a generic callback function which receives any event and an error thrown by
// some function on a higher level.
type ErrorEventHandleFunc func(ctx context.Context, deliveryID string, eventName string, event interface{}, err error) error
type ErrorEventHandleFunc func(ctx context.Context, deliveryID string, eventName string, event any, err error) error

// OnError registers callbacks which are triggered whenever an error occurs.
//
Expand All @@ -194,7 +194,7 @@ type ErrorEventHandleFunc func(ctx context.Context, deliveryID string, eventName
func (g *EventHandler) OnError(callbacks ...ErrorEventHandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.onErrorAny == nil {
Expand All @@ -212,7 +212,7 @@ func (g *EventHandler) OnError(callbacks ...ErrorEventHandleFunc) {
func (g *EventHandler) SetOnError(callbacks ...ErrorEventHandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.onErrorAny == nil {
Expand All @@ -221,7 +221,7 @@ func (g *EventHandler) SetOnError(callbacks ...ErrorEventHandleFunc) {
g.onErrorAny[EventAnyAction] = callbacks
}

func (g *EventHandler) handleError(ctx context.Context, deliveryID string, eventName string, event interface{}, srcErr error) error {
func (g *EventHandler) handleError(ctx context.Context, deliveryID string, eventName string, event any, srcErr error) error {
if event == nil {
return fmt.Errorf("event was empty or nil")
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (g *EventHandler) HandleEventRequest(req *http.Request) error {
}

// HandleEvent executes registered handlers.
func (g *EventHandler) HandleEvent(ctx context.Context, deliveryID string, eventName string, event interface{}) error {
func (g *EventHandler) HandleEvent(ctx context.Context, deliveryID string, eventName string, event any) error {
switch event := event.(type) {
{{ range $_, $webhook := .Webhooks }}
case *github.{{ $webhook.Event }}:
Expand Down
8 changes: 4 additions & 4 deletions gen/template_webhook_event_types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type {{ $webhook.Event }}HandleFunc func(ctx context.Context, deliveryID string,
func (g *EventHandler) On{{ $action.Handler }}(callbacks ...{{ $webhook.Event }}HandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.on{{ $webhook.Event }} == nil {
Expand All @@ -76,7 +76,7 @@ func (g *EventHandler) On{{ $action.Handler }}(callbacks ...{{ $webhook.Event }}
func (g *EventHandler) SetOn{{ $action.Handler }}(callbacks ...{{ $webhook.Event }}HandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.on{{ $webhook.Event }} == nil {
Expand Down Expand Up @@ -139,7 +139,7 @@ func (g *EventHandler) handle{{ $action.Handler }}(ctx context.Context, delivery
func (g *EventHandler) On{{ $webhook.Event }}Any(callbacks ...{{ $webhook.Event }}HandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.on{{ $webhook.Event }} == nil {
Expand All @@ -164,7 +164,7 @@ func (g *EventHandler) On{{ $webhook.Event }}Any(callbacks ...{{ $webhook.Event
func (g *EventHandler) SetOn{{ $webhook.Event }}Any(callbacks ...{{ $webhook.Event }}HandleFunc) {
g.mu.Lock()
defer g.mu.Unlock()
if callbacks == nil || len(callbacks) == 0 {
if len(callbacks) == 0 {
panic("callbacks is nil or empty")
}
if g.on{{ $webhook.Event }} == nil {
Expand Down
24 changes: 12 additions & 12 deletions githubevents/events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions githubevents/events_branch_protection_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading