Skip to content

Commit

Permalink
Merge pull request #70 from atomist-skills/add-sync-eval-function
Browse files Browse the repository at this point in the history
add a function for evaluating policy skill locally
  • Loading branch information
chrispatrick authored Mar 6, 2024
2 parents cbff5ef + 9744c3f commit 1393a15
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions policy/policy_handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ func (h EventHandler) CreateHttpHandler() func(http.ResponseWriter, *http.Reques
return skill.CreateHttpHandler(handlers)
}

func (h EventHandler) ExecuteSyncRequest(ctx context.Context, req skill.RequestContext) ([]goals.GoalEvaluationQueryResult, error) {
handlers := h.createSkillHandlers()

syncHandler, ok := handlers[eventNameLocalEval]
if !ok {
return nil, fmt.Errorf("no handler for sync request")
}

result := syncHandler(ctx, req)

if result.State != skill.Completed {
return nil, fmt.Errorf("sync request did not complete successfully [%s]", result.Reason)
}

return result.SyncRequest.([]goals.GoalEvaluationQueryResult), nil
}

func (h EventHandler) handle(ctx context.Context, req skill.RequestContext) skill.Status {
var (
evaluationMetadata *goals.EvaluationMetadata
Expand Down

0 comments on commit 1393a15

Please sign in to comment.