From f459f8ef7f36228891571e22ac87b11c3a8f548b Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sun, 28 Dec 2025 15:42:04 -0800 Subject: [PATCH] refactor: Extract stepTypeToIssueType helper to remove duplicated switch (bd-j3dj) Extracted duplicated switch statement for mapping step type strings to types.IssueType into a single helper function. This removes code duplication between collectStepsToSubgraph() and collectStepsRecursive(). The new stepTypeToIssueType() function: - Converts 'task', 'bug', 'feature', 'epic', 'chore' to types - Returns types.TypeTask for empty or unrecognized types - Used by both functions with children-override-to-epic logic preserved --- cmd/bd/cook.go | 59 ++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/cmd/bd/cook.go b/cmd/bd/cook.go index 58bb6735..ec015b09 100644 --- a/cmd/bd/cook.go +++ b/cmd/bd/cook.go @@ -16,6 +16,25 @@ import ( "github.com/steveyegge/beads/internal/ui" ) +// stepTypeToIssueType converts a formula step type string to a types.IssueType. +// Returns types.TypeTask for empty or unrecognized types. +func stepTypeToIssueType(stepType string) types.IssueType { + switch stepType { + case "task": + return types.TypeTask + case "bug": + return types.TypeBug + case "feature": + return types.TypeFeature + case "epic": + return types.TypeEpic + case "chore": + return types.TypeChore + default: + return types.TypeTask + } +} + // cookCmd compiles a formula JSON into a proto bead. var cookCmd = &cobra.Command{ Use: "cook ", @@ -419,24 +438,8 @@ func collectStepsToSubgraph(steps []*formula.Step, parentID string, issueMap map // Generate issue ID (formula-name.step-id) issueID := fmt.Sprintf("%s.%s", parentID, step.ID) - // Determine issue type - issueType := types.TypeTask - if step.Type != "" { - switch step.Type { - case "task": - issueType = types.TypeTask - case "bug": - issueType = types.TypeBug - case "feature": - issueType = types.TypeFeature - case "epic": - issueType = types.TypeEpic - case "chore": - issueType = types.TypeChore - } - } - - // If step has children, it's an epic + // Determine issue type (children override to epic) + issueType := stepTypeToIssueType(step.Type) if len(step.Children) > 0 { issueType = types.TypeEpic } @@ -758,24 +761,8 @@ func collectStepsRecursive(steps []*formula.Step, parentID string, idMapping map // Generate issue ID (formula-name.step-id) issueID := fmt.Sprintf("%s.%s", parentID, step.ID) - // Determine issue type - issueType := types.TypeTask - if step.Type != "" { - switch step.Type { - case "task": - issueType = types.TypeTask - case "bug": - issueType = types.TypeBug - case "feature": - issueType = types.TypeFeature - case "epic": - issueType = types.TypeEpic - case "chore": - issueType = types.TypeChore - } - } - - // If step has children, it's an epic + // Determine issue type (children override to epic) + issueType := stepTypeToIssueType(step.Type) if len(step.Children) > 0 { issueType = types.TypeEpic }