Skip to content

Commit d75c716

Browse files
committed
apply feedback
1 parent 50141d9 commit d75c716

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

internal/core/step.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ func (s *Step) UnmarshalJSON(data []byte) error {
165165
return nil
166166
}
167167

168-
// Migrate legacy fields to Commands field
169-
s.Commands = []CommandEntry{
170-
{
168+
// Migrate legacy fields to Commands only when legacy command data exists.
169+
if s.Command != "" || len(s.Args) > 0 || s.CmdWithArgs != "" {
170+
s.Commands = []CommandEntry{{
171171
Command: s.Command,
172172
Args: s.Args,
173173
CmdWithArgs: s.CmdWithArgs,
174-
},
174+
}}
175175
}
176176

177177
return nil

internal/runtime/runner_helper_test.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ func withOutput(output string) stepOption {
7777
}
7878
}
7979

80+
// parseCommand parses a command string into a CommandEntry.
81+
func parseCommand(command string) core.CommandEntry {
82+
cmd, args, err := cmdutil.SplitCommand(command)
83+
if err != nil {
84+
panic(fmt.Errorf("failed to parse command %q: %w", command, err))
85+
}
86+
return core.CommandEntry{
87+
Command: cmd,
88+
Args: args,
89+
CmdWithArgs: command,
90+
}
91+
}
92+
8093
func withCommand(command string) stepOption {
8194
return func(step *core.Step) {
82-
cmd, args, err := cmdutil.SplitCommand(command)
83-
if err != nil {
84-
panic(fmt.Errorf("unexpected: %w", err))
85-
}
86-
step.Commands = []core.CommandEntry{{
87-
Command: cmd,
88-
Args: args,
89-
CmdWithArgs: command,
90-
}}
95+
step.Commands = []core.CommandEntry{parseCommand(command)}
9196
}
9297
}
9398

@@ -133,18 +138,11 @@ func withMaxActiveRuns(n int) runnerOption {
133138
}
134139
}
135140

136-
func newHandlerStep(t *testing.T, name, id, command string) core.Step {
137-
t.Helper()
138-
cmd, args, err := cmdutil.SplitCommand(command)
139-
require.NoError(t, err)
141+
func newHandlerStep(_ *testing.T, name, id, command string) core.Step {
140142
return core.Step{
141-
Name: name,
142-
ID: id,
143-
Commands: []core.CommandEntry{{
144-
Command: cmd,
145-
Args: args,
146-
CmdWithArgs: command,
147-
}},
143+
Name: name,
144+
ID: id,
145+
Commands: []core.CommandEntry{parseCommand(command)},
148146
}
149147
}
150148

0 commit comments

Comments
 (0)