Skip to content

Commit

Permalink
chore(webhook): abstract event processing into generic function
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 committed Dec 29, 2024
1 parent ce8cee9 commit 481d7de
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions webhook/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,30 @@ func (d *Dispatcher) RegisterBugCreateListener(listeners ...BugCreateListener) {
d.bugCreateListeners = append(d.bugCreateListeners, listeners...)
}

func processEvent[L, E any](ctx context.Context, listeners []L, event E, fn func(L, E) error) error {
func processEvent[L, E any](ctx context.Context, listeners []L, event E, fn func(context.Context, L, E) error) error {

Check warning on line 95 in webhook/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

webhook/dispatcher.go#L95

Added line #L95 was not covered by tests
eg, ctx := errgroup.WithContext(ctx)
for _, listener := range listeners {

Check warning on line 97 in webhook/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

webhook/dispatcher.go#L97

Added line #L97 was not covered by tests
eg.Go(func() error {
return fn(listener, event)
return fn(ctx, listener, event)

Check warning on line 99 in webhook/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

webhook/dispatcher.go#L99

Added line #L99 was not covered by tests
})
}
return eg.Wait()
}

func (d *Dispatcher) processStoryCreate(ctx context.Context, event *StoryCreateEvent) error {
return processEvent(ctx, d.storyCreateListeners, event, func(listener StoryCreateListener, event *StoryCreateEvent) error {
return processEvent(ctx, d.storyCreateListeners, event, func(ctx context.Context, listener StoryCreateListener, event *StoryCreateEvent) error {
return listener.OnStoryCreate(ctx, event)
})

Check warning on line 108 in webhook/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

webhook/dispatcher.go#L105-L108

Added lines #L105 - L108 were not covered by tests
}

func (d *Dispatcher) processStoryUpdate(ctx context.Context, event *StoryUpdateEvent) error {
return processEvent(ctx, d.storyUpdateListeners, event, func(listener StoryUpdateListener, event *StoryUpdateEvent) error {
return processEvent(ctx, d.storyUpdateListeners, event, func(ctx context.Context, listener StoryUpdateListener, event *StoryUpdateEvent) error {
return listener.OnStoryUpdate(ctx, event)
})

Check warning on line 114 in webhook/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

webhook/dispatcher.go#L112-L114

Added lines #L112 - L114 were not covered by tests
}

func (d *Dispatcher) processBugCreate(ctx context.Context, event *BugCreateEvent) error {
return processEvent(ctx, d.bugCreateListeners, event, func(listener BugCreateListener, event *BugCreateEvent) error {
return processEvent(ctx, d.bugCreateListeners, event, func(ctx context.Context, listener BugCreateListener, event *BugCreateEvent) error {
return listener.OnBugCreate(ctx, event)
})

Check warning on line 120 in webhook/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

webhook/dispatcher.go#L118-L120

Added lines #L118 - L120 were not covered by tests
}

0 comments on commit 481d7de

Please sign in to comment.