Skip to content

Commit c7a811e

Browse files
committed
fix(agent-task create): use pager when following logs
Signed-off-by: Babak K. Shandiz <babakks@github.com>
1 parent cb9808f commit c7a811e

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

pkg/cmd/agent-task/create/create.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ func createRun(opts *CreateOptions) error {
162162
return err
163163
}
164164

165+
if opts.Follow {
166+
return followLogs(opts, client, job.SessionID)
167+
}
168+
165169
sessionURL, err := fetchJobSessionURL(ctx, client, repo, job, opts.BackOff)
166170
opts.IO.StopProgressIndicator()
167171

@@ -177,9 +181,6 @@ func createRun(opts *CreateOptions) error {
177181
fmt.Fprintf(opts.IO.Out, "job %s queued. View progress: %s\n", job.ID, capi.AgentsHomeURL)
178182
}
179183

180-
if opts.Follow {
181-
return followLogs(opts, client, job.SessionID)
182-
}
183184
return nil
184185
}
185186

@@ -250,8 +251,13 @@ func fetchJobWithBackoff(ctx context.Context, client capi.CapiClient, repo ghrep
250251
}
251252

252253
func followLogs(opts *CreateOptions, capiClient capi.CapiClient, sessionID string) error {
253-
ctx := context.Background()
254+
if err := opts.IO.StartPager(); err == nil {
255+
defer opts.IO.StopPager()
256+
} else {
257+
fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err)
258+
}
254259

260+
ctx := context.Background()
255261
renderer := opts.LogRenderer()
256262

257263
var called bool
@@ -267,6 +273,5 @@ func followLogs(opts *CreateOptions, capiClient capi.CapiClient, sessionID strin
267273
return raw, nil
268274
}
269275

270-
fmt.Fprintln(opts.IO.Out, "")
271276
return renderer.Follow(fetcher, opts.IO.Out, opts.IO)
272277
}

pkg/cmd/agent-task/create/create_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,6 @@ func Test_createRun(t *testing.T) {
473473
}
474474
},
475475
wantStdout: heredoc.Doc(`
476-
https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1
477-
478476
(rendered:) <raw-logs-one>
479477
(rendered:) <raw-logs-two>
480478
`),

0 commit comments

Comments
 (0)