Skip to content

Commit e8c2980

Browse files
committed
Fix auto-selected job lost between polling iterations and remove redundant joinLines
- Capture jobKey after first successful auto-selection so subsequent iterations don't fail if additional jobs appear during workflow expansion - Replace custom joinLines function with strings.Join from standard library
1 parent e029c95 commit e8c2980

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

pkg/cmd/ci/ssh.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"os"
9+
"strings"
910
"time"
1011

1112
"github.com/depot/cli/pkg/api"
@@ -139,6 +140,12 @@ func waitForSandbox(ctx context.Context, token, orgID, runID, jobKey string) (sa
139140
return "", "", err
140141
}
141142

143+
// Capture the job key after first successful auto-selection so that
144+
// subsequent iterations don't fail if additional jobs appear.
145+
if jobKey == "" {
146+
jobKey = targetJob.JobKey
147+
}
148+
142149
attempt := latestAttempt(targetJob)
143150
if attempt == nil {
144151
if currentState != stateWaitingForStart {
@@ -212,7 +219,7 @@ func findJob(resp *civ1.GetRunStatusResponse, jobKey string) (*civ1.JobStatus, e
212219
for i, j := range allJobs {
213220
keys[i] = fmt.Sprintf(" %s (%s)", j.JobKey, j.Status)
214221
}
215-
return nil, fmt.Errorf("run has multiple jobs, specify one with --job:\n%s", joinLines(keys))
222+
return nil, fmt.Errorf("run has multiple jobs, specify one with --job:\n%s", strings.Join(keys, "\n"))
216223
}
217224

218225
func latestAttempt(job *civ1.JobStatus) *civ1.AttemptStatus {
@@ -228,17 +235,6 @@ func latestAttempt(job *civ1.JobStatus) *civ1.AttemptStatus {
228235
return latest
229236
}
230237

231-
func joinLines(lines []string) string {
232-
result := ""
233-
for i, l := range lines {
234-
if i > 0 {
235-
result += "\n"
236-
}
237-
result += l
238-
}
239-
return result
240-
}
241-
242238
func printSSHInfo(sandboxID, sessionID, output string) error {
243239
if output == "json" {
244240
enc := json.NewEncoder(os.Stdout)

0 commit comments

Comments
 (0)