Skip to content

Commit f0a0c4b

Browse files
committed
fix(agent-task view): display zero premium requests
Signed-off-by: Babak K. Shandiz <babakks@github.com>
1 parent 6927d64 commit f0a0c4b

2 files changed

Lines changed: 88 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,15 @@ func printSession(opts *ViewOptions, session *capi.Session) {
307307
fmt.Fprintf(opts.IO.Out, "Started %s\n", text.FuzzyAgo(time.Now(), session.CreatedAt))
308308
}
309309

310-
additionalNotes := make([]string, 0, 2)
311-
312-
if session.PremiumRequests > 0 {
313-
s := strings.TrimSuffix(fmt.Sprintf("%.1f", session.PremiumRequests), ".0")
314-
additionalNotes = append(additionalNotes, fmt.Sprintf("Used %s premium request(s)", s))
315-
}
310+
usedPremiumRequests := strings.TrimSuffix(fmt.Sprintf("%.1f", session.PremiumRequests), ".0")
311+
usedPremiumRequestsNote := fmt.Sprintf("Used %s premium request(s)", usedPremiumRequests)
316312

313+
var durationNote string
317314
if session.CompletedAt.After(session.CreatedAt) {
318-
additionalNotes = append(additionalNotes, fmt.Sprintf("Duration %s", session.CompletedAt.Sub(session.CreatedAt).Round(time.Second).String()))
315+
durationNote = fmt.Sprintf("Duration %s", session.CompletedAt.Sub(session.CreatedAt).Round(time.Second).String())
319316
}
320317

321-
if len(additionalNotes) > 0 {
322-
fmt.Fprintf(opts.IO.Out, "%s\n", cs.Muted(strings.Join(additionalNotes, " • ")))
323-
}
318+
fmt.Fprintf(opts.IO.Out, "%s%s\n", cs.Muted(usedPremiumRequestsNote), cs.Muted(durationNote))
324319

325320
if !opts.Log {
326321
fmt.Fprintln(opts.IO.Out, "")

pkg/cmd/agent-task/view/view_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,89 @@ func Test_viewRun(t *testing.T) {
345345
gh agent-task view 'some-session-id' --log
346346
`),
347347
},
348+
{
349+
name: "with session id, success, with zero premium requests (tty)",
350+
tty: true,
351+
opts: ViewOptions{
352+
SelectorArg: "some-session-id",
353+
SessionID: "some-session-id",
354+
},
355+
capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
356+
m.GetSessionFunc = func(_ context.Context, id string) (*capi.Session, error) {
357+
assert.Equal(t, "some-session-id", id)
358+
return &capi.Session{
359+
ID: "some-session-id",
360+
State: "completed",
361+
CreatedAt: sampleDate,
362+
CompletedAt: sampleCompletedAt,
363+
PremiumRequests: 0,
364+
PullRequest: &api.PullRequest{
365+
Title: "fix something",
366+
Number: 101,
367+
URL: "https://github.com/OWNER/REPO/pull/101",
368+
Repository: &api.PRRepository{
369+
NameWithOwner: "OWNER/REPO",
370+
},
371+
},
372+
User: &api.GitHubUser{
373+
Login: "octocat",
374+
},
375+
}, nil
376+
}
377+
},
378+
wantOut: heredoc.Doc(`
379+
Ready for review • fix something • OWNER/REPO#101
380+
Started on behalf of octocat about 6 hours ago
381+
Used 0 premium request(s) • Duration 5m0s
382+
383+
For detailed session logs, try:
384+
gh agent-task view 'some-session-id' --log
385+
386+
View this session on GitHub:
387+
https://github.com/OWNER/REPO/pull/101/agent-sessions/some-session-id
388+
`),
389+
},
390+
{
391+
name: "with session id, success, duration not available (tty)",
392+
tty: true,
393+
opts: ViewOptions{
394+
SelectorArg: "some-session-id",
395+
SessionID: "some-session-id",
396+
},
397+
capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
398+
m.GetSessionFunc = func(_ context.Context, id string) (*capi.Session, error) {
399+
assert.Equal(t, "some-session-id", id)
400+
return &capi.Session{
401+
ID: "some-session-id",
402+
State: "in_progress",
403+
CreatedAt: sampleDate,
404+
PremiumRequests: 1.5,
405+
PullRequest: &api.PullRequest{
406+
Title: "fix something",
407+
Number: 101,
408+
URL: "https://github.com/OWNER/REPO/pull/101",
409+
Repository: &api.PRRepository{
410+
NameWithOwner: "OWNER/REPO",
411+
},
412+
},
413+
User: &api.GitHubUser{
414+
Login: "octocat",
415+
},
416+
}, nil
417+
}
418+
},
419+
wantOut: heredoc.Doc(`
420+
In progress • fix something • OWNER/REPO#101
421+
Started on behalf of octocat about 6 hours ago
422+
Used 1.5 premium request(s)
423+
424+
For detailed session logs, try:
425+
gh agent-task view 'some-session-id' --log
426+
427+
View this session on GitHub:
428+
https://github.com/OWNER/REPO/pull/101/agent-sessions/some-session-id
429+
`),
430+
},
348431
{
349432
name: "with session id, not found, web mode (tty)",
350433
tty: true,

0 commit comments

Comments
 (0)