Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typo): fix RepositoryEventCreated name #10

Merged
merged 1 commit into from
Apr 29, 2022
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
2 changes: 1 addition & 1 deletion gen/template_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ var params = TemplateParameters{
Name: "repository",
Actions: []Action{
{
Handler: "RepositoryEvenCreated",
Handler: "RepositoryEventCreated",
Action: "created",
},
{
Expand Down
36 changes: 18 additions & 18 deletions githubevents/events_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
48 changes: 24 additions & 24 deletions githubevents/events_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestHandleRepositoryEventAny(t *testing.T) {
}
}

func TestOnRepositoryEvenCreated(t *testing.T) {
func TestOnRepositoryEventCreated(t *testing.T) {
type args struct {
callbacks []RepositoryEventHandleFunc
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
})
}
Expand Down Expand Up @@ -1912,7 +1912,7 @@ func TestRepositoryEvent(t *testing.T) {
},

{
name: "must trigger RepositoryEvenCreated",
name: "must trigger RepositoryEventCreated",
fields: fields{
handler: &EventHandler{
WebhookSecret: "fake",
Expand All @@ -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
},
},
Expand All @@ -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",
Expand All @@ -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
},
},
Expand All @@ -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",
Expand All @@ -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
},
},
Expand Down