diff --git a/gen/template_params.go b/gen/template_params.go index d7d5beb..4586591 100644 --- a/gen/template_params.go +++ b/gen/template_params.go @@ -776,7 +776,7 @@ var params = TemplateParameters{ Name: "repository", Actions: []Action{ { - Handler: "RepositoryEvenCreated", + Handler: "RepositoryEventCreated", Action: "created", }, { diff --git a/githubevents/events_repository.go b/githubevents/events_repository.go index a236ddf..867599c 100644 --- a/githubevents/events_repository.go +++ b/githubevents/events_repository.go @@ -22,9 +22,9 @@ const ( // listening to all events of type github.RepositoryEvent RepositoryEventAnyAction = "*" - // RepositoryEvenCreatedAction is used to identify callbacks + // RepositoryEventCreatedAction is used to identify callbacks // listening to events of type github.RepositoryEvent and action "created" - RepositoryEvenCreatedAction = "created" + RepositoryEventCreatedAction = "created" // RepositoryEventDeletedAction is used to identify callbacks // listening to events of type github.RepositoryEvent and action "deleted" @@ -65,14 +65,14 @@ const ( // event (type: *github.RepositoryEvent) is the webhook payload. type RepositoryEventHandleFunc func(deliveryID string, eventName string, event *github.RepositoryEvent) error -// OnRepositoryEvenCreated registers callbacks listening to events of type github.RepositoryEvent. +// OnRepositoryEventCreated registers callbacks listening to events of type github.RepositoryEvent. // // This function appends the callbacks passed as arguments to already existing ones. -// If already existing callbacks are to be overwritten, SetOnRepositoryEvenCreated must be used. +// If already existing callbacks are to be overwritten, SetOnRepositoryEventCreated must be used. // // Callbacks are executed in parallel. This function 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. -func (g *EventHandler) OnRepositoryEvenCreated(callbacks ...RepositoryEventHandleFunc) { +func (g *EventHandler) OnRepositoryEventCreated(callbacks ...RepositoryEventHandleFunc) { g.mu.Lock() defer g.mu.Unlock() if callbacks == nil || len(callbacks) == 0 { @@ -81,21 +81,21 @@ func (g *EventHandler) OnRepositoryEvenCreated(callbacks ...RepositoryEventHandl if g.onRepositoryEvent == nil { g.onRepositoryEvent = make(map[string][]RepositoryEventHandleFunc) } - g.onRepositoryEvent[RepositoryEvenCreatedAction] = append( - g.onRepositoryEvent[RepositoryEvenCreatedAction], + g.onRepositoryEvent[RepositoryEventCreatedAction] = append( + g.onRepositoryEvent[RepositoryEventCreatedAction], callbacks..., ) } -// SetOnRepositoryEvenCreated registers callbacks listening to events of type github.RepositoryEvent +// SetOnRepositoryEventCreated registers callbacks listening to events of type github.RepositoryEvent // and overwrites already registered callbacks. // // This function overwrites all previously registered callbacks. -// If already registered callbacks are not to be overwritten, OnRepositoryEvenCreatedAny must be used. +// If already registered callbacks are not to be overwritten, OnRepositoryEventCreatedAny must be used. // // Callbacks are executed in parallel. This function 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. -func (g *EventHandler) SetOnRepositoryEvenCreated(callbacks ...RepositoryEventHandleFunc) { +func (g *EventHandler) SetOnRepositoryEventCreated(callbacks ...RepositoryEventHandleFunc) { g.mu.Lock() defer g.mu.Unlock() if callbacks == nil || len(callbacks) == 0 { @@ -104,23 +104,23 @@ func (g *EventHandler) SetOnRepositoryEvenCreated(callbacks ...RepositoryEventHa if g.onRepositoryEvent == nil { g.onRepositoryEvent = make(map[string][]RepositoryEventHandleFunc) } - g.onRepositoryEvent[RepositoryEvenCreatedAction] = callbacks + g.onRepositoryEvent[RepositoryEventCreatedAction] = callbacks } -func (g *EventHandler) handleRepositoryEvenCreated(deliveryID string, eventName string, event *github.RepositoryEvent) error { +func (g *EventHandler) handleRepositoryEventCreated(deliveryID string, eventName string, event *github.RepositoryEvent) error { if event == nil || event.Action == nil || *event.Action == "" { return fmt.Errorf("event action was empty or nil") } - if RepositoryEvenCreatedAction != *event.Action { + if RepositoryEventCreatedAction != *event.Action { return fmt.Errorf( - "handleRepositoryEvenCreated() called with wrong action, want %s, got %s", - RepositoryEvenCreatedAction, + "handleRepositoryEventCreated() called with wrong action, want %s, got %s", + RepositoryEventCreatedAction, *event.Action, ) } eg := new(errgroup.Group) for _, action := range []string{ - RepositoryEvenCreatedAction, + RepositoryEventCreatedAction, RepositoryEventAnyAction, } { if _, ok := g.onRepositoryEvent[action]; ok { @@ -847,8 +847,8 @@ func (g *EventHandler) RepositoryEvent(deliveryID string, eventName string, even switch action { - case RepositoryEvenCreatedAction: - err := g.handleRepositoryEvenCreated(deliveryID, eventName, event) + case RepositoryEventCreatedAction: + err := g.handleRepositoryEventCreated(deliveryID, eventName, event) if err != nil { return g.handleError(deliveryID, eventName, event, err) } diff --git a/githubevents/events_repository_test.go b/githubevents/events_repository_test.go index fe43c83..9d34902 100644 --- a/githubevents/events_repository_test.go +++ b/githubevents/events_repository_test.go @@ -173,7 +173,7 @@ func TestHandleRepositoryEventAny(t *testing.T) { } } -func TestOnRepositoryEvenCreated(t *testing.T) { +func TestOnRepositoryEventCreated(t *testing.T) { type args struct { callbacks []RepositoryEventHandleFunc } @@ -208,15 +208,15 @@ func TestOnRepositoryEvenCreated(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := New("fake") - g.OnRepositoryEvenCreated(tt.args.callbacks...) - if len(g.onRepositoryEvent[RepositoryEvenCreatedAction]) == 0 { - t.Errorf("failed to add callbacks, got %d", len(g.onRepositoryEvent[RepositoryEvenCreatedAction])) + g.OnRepositoryEventCreated(tt.args.callbacks...) + if len(g.onRepositoryEvent[RepositoryEventCreatedAction]) == 0 { + t.Errorf("failed to add callbacks, got %d", len(g.onRepositoryEvent[RepositoryEventCreatedAction])) } }) } } -func TestSetOnRepositoryEvenCreated(t *testing.T) { +func TestSetOnRepositoryEventCreated(t *testing.T) { type args struct { callbacks []RepositoryEventHandleFunc } @@ -255,19 +255,19 @@ func TestSetOnRepositoryEvenCreated(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := New("fake") // add callbacks to be overwritten - g.SetOnRepositoryEvenCreated(func(deliveryID string, eventName string, event *github.RepositoryEvent) error { + g.SetOnRepositoryEventCreated(func(deliveryID string, eventName string, event *github.RepositoryEvent) error { return nil }) - g.SetOnRepositoryEvenCreated(tt.args.callbacks...) - if len(g.onRepositoryEvent[RepositoryEvenCreatedAction]) != tt.want { - t.Errorf("failed to add callbacks, got %d, want %d", len(g.onRepositoryEvent[RepositoryEvenCreatedAction]), tt.want) + g.SetOnRepositoryEventCreated(tt.args.callbacks...) + if len(g.onRepositoryEvent[RepositoryEventCreatedAction]) != tt.want { + t.Errorf("failed to add callbacks, got %d, want %d", len(g.onRepositoryEvent[RepositoryEventCreatedAction]), tt.want) } }) } } -func TestHandleRepositoryEvenCreated(t *testing.T) { - action := RepositoryEvenCreatedAction +func TestHandleRepositoryEventCreated(t *testing.T) { + action := RepositoryEventCreatedAction emptyAction := "" fakeAction := "doesntexist" @@ -347,14 +347,14 @@ func TestHandleRepositoryEvenCreated(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := New("fake") - g.OnRepositoryEvenCreated(func(deliveryID string, eventName string, event *github.RepositoryEvent) error { + g.OnRepositoryEventCreated(func(deliveryID string, eventName string, event *github.RepositoryEvent) error { if tt.args.fail { return errors.New("fake error") } return nil }) - if err := g.handleRepositoryEvenCreated(tt.args.deliveryID, tt.args.eventName, tt.args.event); (err != nil) != tt.wantErr { - t.Errorf("handleRepositoryEvenCreated() error = %v, wantErr %v", err, tt.wantErr) + if err := g.handleRepositoryEventCreated(tt.args.deliveryID, tt.args.eventName, tt.args.event); (err != nil) != tt.wantErr { + t.Errorf("handleRepositoryEventCreated() error = %v, wantErr %v", err, tt.wantErr) } }) } @@ -1912,7 +1912,7 @@ func TestRepositoryEvent(t *testing.T) { }, { - name: "must trigger RepositoryEvenCreated", + name: "must trigger RepositoryEventCreated", fields: fields{ handler: &EventHandler{ WebhookSecret: "fake", @@ -1939,9 +1939,9 @@ func TestRepositoryEvent(t *testing.T) { return nil }, }, - RepositoryEvenCreatedAction: { + RepositoryEventCreatedAction: { func(deliveryID string, eventName string, event *github.RepositoryEvent) error { - t.Logf("%s action called", RepositoryEvenCreatedAction) + t.Logf("%s action called", RepositoryEventCreatedAction) return nil }, }, @@ -1951,12 +1951,12 @@ func TestRepositoryEvent(t *testing.T) { args: args{ deliveryID: "42", eventName: "repository", - event: &github.RepositoryEvent{Action: ptrString(RepositoryEvenCreatedAction)}, + event: &github.RepositoryEvent{Action: ptrString(RepositoryEventCreatedAction)}, }, wantErr: false, }, { - name: "must fail RepositoryEvenCreated with empty action", + name: "must fail RepositoryEventCreated with empty action", fields: fields{ handler: &EventHandler{ WebhookSecret: "fake", @@ -1983,9 +1983,9 @@ func TestRepositoryEvent(t *testing.T) { return nil }, }, - RepositoryEvenCreatedAction: { + RepositoryEventCreatedAction: { func(deliveryID string, eventName string, event *github.RepositoryEvent) error { - t.Logf("%s action called", RepositoryEvenCreatedAction) + t.Logf("%s action called", RepositoryEventCreatedAction) return nil }, }, @@ -2000,7 +2000,7 @@ func TestRepositoryEvent(t *testing.T) { wantErr: true, }, { - name: "must fail RepositoryEvenCreated with nil action", + name: "must fail RepositoryEventCreated with nil action", fields: fields{ handler: &EventHandler{ WebhookSecret: "fake", @@ -2027,9 +2027,9 @@ func TestRepositoryEvent(t *testing.T) { return nil }, }, - RepositoryEvenCreatedAction: { + RepositoryEventCreatedAction: { func(deliveryID string, eventName string, event *github.RepositoryEvent) error { - t.Logf("%s action called", RepositoryEvenCreatedAction) + t.Logf("%s action called", RepositoryEventCreatedAction) return nil }, },