Skip to content

Commit

Permalink
feat: extract task title generation (#58)
Browse files Browse the repository at this point in the history
Because

- INS-3584 (README auto-gen) needs to build the task title in case it
isn't
  defined in the task schema.

This commit

- Extracts the already implemented code for task titles to a public
method.
  • Loading branch information
jvallesm committed Feb 22, 2024
1 parent f18307b commit 52804d4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/base/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ func convertDataSpecToCompSpec(dataSpec *structpb.Struct) (*structpb.Struct, err
return compSpec, nil
}

const taskPrefix = "TASK_"

// TaskIDToTitle builds a Task title from its ID. This is used when the `title`
// key in the task definition isn't present.
func TaskIDToTitle(id string) string {
title := strings.ReplaceAll(id, taskPrefix, "")
title = strings.ReplaceAll(title, "_", " ")
return cases.Title(language.English).String(title)
}

func (comp *Component) generateComponentTasks(availableTasks []string) []*pipelinePB.ComponentTask {
tasks := make([]*pipelinePB.ComponentTask, 0, len(availableTasks))
for _, t := range availableTasks {
Expand Down

0 comments on commit 52804d4

Please sign in to comment.