Skip to content

Commit

Permalink
move sync query support to new opt
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Norton committed Jan 2, 2024
1 parent c6c1739 commit b330d7f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions policy/policy_handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (

var defaultOpts = []Opt{
withAsync(),
withSubscription(),
}

func NewPolicyEventHandler(subscriptionNames []string, evalSelector EvaluatorSelector, opts ...Opt) EventHandler {
Expand Down
17 changes: 1 addition & 16 deletions policy/policy_handler/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ package policy_handler

import (
"context"
"fmt"

"github.com/atomist-skills/go-skill"
"github.com/atomist-skills/go-skill/policy/data"
"olympos.io/encoding/edn"
)

func WithSubscription() Opt {
func withSubscription() Opt {
return func(h *EventHandler) {
h.subscriptionDataProviders = append(h.subscriptionDataProviders, getSubscriptionData)
h.dataSourceProviders = append(h.dataSourceProviders, getSyncDataSources)
}
}

Expand All @@ -23,14 +19,3 @@ func getSubscriptionData(ctx context.Context, req skill.RequestContext) ([][]edn

return req.Event.Context.Subscription.Result, req.Event.Context.Subscription.Configuration, nil
}

func getSyncDataSources(ctx context.Context, req skill.RequestContext) ([]data.DataSource, error) {
gqlDs, err := data.NewSyncGraphqlDataSource(ctx, req)
if err != nil {
return nil, fmt.Errorf("unable to create data source: %w", err)
}

return []data.DataSource{
gqlDs,
}, nil
}
25 changes: 25 additions & 0 deletions policy/policy_handler/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package policy_handler

import (
"context"
"fmt"
"github.com/atomist-skills/go-skill"
"github.com/atomist-skills/go-skill/policy/data"
)

func WithSyncQuery() Opt {
return func(h *EventHandler) {
h.dataSourceProviders = append(h.dataSourceProviders, getSyncDataSources)
}
}

func getSyncDataSources(ctx context.Context, req skill.RequestContext) ([]data.DataSource, error) {
gqlDs, err := data.NewSyncGraphqlDataSource(ctx, req)
if err != nil {
return nil, fmt.Errorf("unable to create data source: %w", err)
}

return []data.DataSource{
gqlDs,
}, nil
}

0 comments on commit b330d7f

Please sign in to comment.