Skip to content

Commit

Permalink
refactor: change WorkflowStepCompleted args
Browse files Browse the repository at this point in the history
  • Loading branch information
nakatanakatana committed Jun 14, 2022
1 parent 5547165 commit f55b7c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions workflow_step_execute.go
Expand Up @@ -19,14 +19,25 @@ type (
}
)

type WorkflowStepCompletedRequestOption func(opt WorkflowStepCompletedRequest) error

func WorkflowStepCompletedRequestOptionOutput(outputs map[string]string) WorkflowStepCompletedRequestOption {
return func(opt WorkflowStepCompletedRequest) error {
if len(outputs) > 0 {
opt.Outputs = &outputs
}
return nil
}
}

// WorkflowStepCompleted indicates step is completed
func (api *Client) WorkflowStepCompleted(workflowStepExecuteID string, outputs *map[string]string) error {
func (api *Client) WorkflowStepCompleted(workflowStepExecuteID string, options ...WorkflowStepCompletedRequestOption) error {
// More information: https://api.slack.com/methods/workflows.stepCompleted
r := WorkflowStepCompletedRequest{
WorkflowStepExecuteID: workflowStepExecuteID,
}
if outputs != nil {
r.Outputs = outputs
for _, option := range options {
option(r)
}

endpoint := api.endpoint + "workflows.stepCompleted"
Expand Down
2 changes: 1 addition & 1 deletion workflow_step_execute_test.go
Expand Up @@ -19,7 +19,7 @@ func TestWorkflowStepCompleted(t *testing.T) {
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))

if err := api.WorkflowStepCompleted("executeID", nil); err != nil {
if err := api.WorkflowStepCompleted("executeID"); err != nil {
t.Errorf("Unexpected error: %s", err)
}
}
Expand Down

0 comments on commit f55b7c9

Please sign in to comment.