Skip to content

Commit ecfbb67

Browse files
committed
fix(agent-task view): improve session overview
Signed-off-by: Babak K. Shandiz <babakks@github.com>
1 parent 3e43a98 commit ecfbb67

2 files changed

Lines changed: 53 additions & 24 deletions

File tree

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,10 @@ func viewRun(opts *ViewOptions) error {
296296
func printSession(opts *ViewOptions, session *capi.Session) {
297297
cs := opts.IO.ColorScheme()
298298

299-
if session.PullRequest != nil {
300-
fmt.Fprintf(opts.IO.Out, "%s • %s • %s%s\n",
301-
shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)),
302-
cs.Bold(session.PullRequest.Title),
303-
session.PullRequest.Repository.NameWithOwner,
304-
cs.ColorFromString(prShared.ColorForPRState(*session.PullRequest))(fmt.Sprintf("#%d", session.PullRequest.Number)),
305-
)
306-
} else {
307-
// This can happen when the session is just created and a PR is not yet available for it
308-
fmt.Fprintf(opts.IO.Out, "%s\n", shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)))
309-
}
299+
fmt.Fprintf(opts.IO.Out, "%s • %s\n",
300+
shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)),
301+
cs.Bold(session.Name),
302+
)
310303

311304
if session.User != nil {
312305
fmt.Fprintf(opts.IO.Out, "Started on behalf of %s %s\n", session.User.Login, text.FuzzyAgo(time.Now(), session.CreatedAt))
@@ -325,6 +318,15 @@ func printSession(opts *ViewOptions, session *capi.Session) {
325318

326319
fmt.Fprintf(opts.IO.Out, "%s%s\n", cs.Muted(usedPremiumRequestsNote), cs.Muted(durationNote))
327320

321+
// Note that when the session is just created, a PR is not yet available for it.
322+
if session.PullRequest != nil {
323+
fmt.Fprintf(opts.IO.Out, "\n%s%s • %s\n",
324+
session.PullRequest.Repository.NameWithOwner,
325+
cs.ColorFromString(prShared.ColorForPRState(*session.PullRequest))(fmt.Sprintf("#%d", session.PullRequest.Number)),
326+
cs.Bold(session.PullRequest.Title),
327+
)
328+
}
329+
328330
if session.Error != nil {
329331
var workflowRunURL string
330332
if session.WorkflowRunID != 0 && session.PullRequest != nil {
@@ -347,9 +349,9 @@ func printSession(opts *ViewOptions, session *capi.Session) {
347349
}
348350

349351
if !opts.Log {
350-
fmt.Fprintf(opts.IO.Out, "\nFor detailed session logs, try:\ngh agent-task view '%s' --log\n", session.ID)
352+
fmt.Fprint(opts.IO.Out, cs.Mutedf("\nFor detailed session logs, try:\ngh agent-task view '%s' --log\n", session.ID))
351353
} else if !opts.Follow {
352-
fmt.Fprintf(opts.IO.Out, "\nTo follow session logs, try:\ngh agent-task view '%s' --log --follow\n", session.ID)
354+
fmt.Fprint(opts.IO.Out, cs.Mutedf("\nTo follow session logs, try:\ngh agent-task view '%s' --log --follow\n", session.ID))
353355
}
354356

355357
if session.PullRequest != nil {

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func Test_viewRun(t *testing.T) {
215215
return &capi.Session{
216216
ID: "some-session-id",
217217
State: "completed",
218+
Name: "session one",
218219
CreatedAt: sampleDate,
219220
CompletedAt: sampleCompletedAt,
220221
PremiumRequests: 1.5,
@@ -233,10 +234,12 @@ func Test_viewRun(t *testing.T) {
233234
}
234235
},
235236
wantOut: heredoc.Doc(`
236-
Ready for review • fix something • OWNER/REPO#101
237+
Ready for review • session one
237238
Started on behalf of octocat about 6 hours ago
238239
Used 1.5 premium request(s) • Duration 5m0s
239240
241+
OWNER/REPO#101 • fix something
242+
240243
For detailed session logs, try:
241244
gh agent-task view 'some-session-id' --log
242245
@@ -258,6 +261,7 @@ func Test_viewRun(t *testing.T) {
258261
return &capi.Session{
259262
ID: "some-session-id",
260263
State: "completed",
264+
Name: "session one",
261265
CreatedAt: sampleDate,
262266
CompletedAt: sampleCompletedAt,
263267
PremiumRequests: 1.5,
@@ -273,10 +277,12 @@ func Test_viewRun(t *testing.T) {
273277
}
274278
},
275279
wantOut: heredoc.Doc(`
276-
Ready for review • fix something • OWNER/REPO#101
280+
Ready for review • session one
277281
Started about 6 hours ago
278282
Used 1.5 premium request(s) • Duration 5m0s
279283
284+
OWNER/REPO#101 • fix something
285+
280286
For detailed session logs, try:
281287
gh agent-task view 'some-session-id' --log
282288
@@ -298,6 +304,7 @@ func Test_viewRun(t *testing.T) {
298304
return &capi.Session{
299305
ID: "some-session-id",
300306
State: "completed",
307+
Name: "session one",
301308
CreatedAt: sampleDate,
302309
CompletedAt: sampleCompletedAt,
303310
PremiumRequests: 1.5,
@@ -308,7 +315,7 @@ func Test_viewRun(t *testing.T) {
308315
}
309316
},
310317
wantOut: heredoc.Doc(`
311-
Ready for review
318+
Ready for review • session one
312319
Started on behalf of octocat about 6 hours ago
313320
Used 1.5 premium request(s) • Duration 5m0s
314321
@@ -330,14 +337,15 @@ func Test_viewRun(t *testing.T) {
330337
return &capi.Session{
331338
ID: "some-session-id",
332339
State: "completed",
340+
Name: "session one",
333341
CreatedAt: sampleDate,
334342
CompletedAt: sampleCompletedAt,
335343
PremiumRequests: 1.5,
336344
}, nil
337345
}
338346
},
339347
wantOut: heredoc.Doc(`
340-
Ready for review
348+
Ready for review • session one
341349
Started about 6 hours ago
342350
Used 1.5 premium request(s) • Duration 5m0s
343351
@@ -358,6 +366,7 @@ func Test_viewRun(t *testing.T) {
358366
return &capi.Session{
359367
ID: "some-session-id",
360368
State: "completed",
369+
Name: "session one",
361370
CreatedAt: sampleDate,
362371
CompletedAt: sampleCompletedAt,
363372
PremiumRequests: 0,
@@ -376,10 +385,12 @@ func Test_viewRun(t *testing.T) {
376385
}
377386
},
378387
wantOut: heredoc.Doc(`
379-
Ready for review • fix something • OWNER/REPO#101
388+
Ready for review • session one
380389
Started on behalf of octocat about 6 hours ago
381390
Used 0 premium request(s) • Duration 5m0s
382391
392+
OWNER/REPO#101 • fix something
393+
383394
For detailed session logs, try:
384395
gh agent-task view 'some-session-id' --log
385396
@@ -400,6 +411,7 @@ func Test_viewRun(t *testing.T) {
400411
return &capi.Session{
401412
ID: "some-session-id",
402413
State: "in_progress",
414+
Name: "session one",
403415
CreatedAt: sampleDate,
404416
PremiumRequests: 1.5,
405417
PullRequest: &api.PullRequest{
@@ -417,10 +429,12 @@ func Test_viewRun(t *testing.T) {
417429
}
418430
},
419431
wantOut: heredoc.Doc(`
420-
In progress • fix something • OWNER/REPO#101
432+
In progress • session one
421433
Started on behalf of octocat about 6 hours ago
422434
Used 1.5 premium request(s)
423435
436+
OWNER/REPO#101 • fix something
437+
424438
For detailed session logs, try:
425439
gh agent-task view 'some-session-id' --log
426440
@@ -441,6 +455,7 @@ func Test_viewRun(t *testing.T) {
441455
return &capi.Session{
442456
ID: "some-session-id",
443457
State: "failed",
458+
Name: "session one",
444459
CreatedAt: sampleDate,
445460
PremiumRequests: 1.5,
446461
Error: &capi.SessionError{
@@ -461,10 +476,12 @@ func Test_viewRun(t *testing.T) {
461476
}
462477
},
463478
wantOut: heredoc.Doc(`
464-
Failed • fix something • OWNER/REPO#101
479+
Failed • session one
465480
Started on behalf of octocat about 6 hours ago
466481
Used 1.5 premium request(s)
467482
483+
OWNER/REPO#101 • fix something
484+
468485
X blah blah
469486
470487
For detailed session logs, try:
@@ -487,6 +504,7 @@ func Test_viewRun(t *testing.T) {
487504
return &capi.Session{
488505
ID: "some-session-id",
489506
State: "failed",
507+
Name: "session one",
490508
CreatedAt: sampleDate,
491509
PremiumRequests: 1.5,
492510
WorkflowRunID: 9999,
@@ -508,10 +526,12 @@ func Test_viewRun(t *testing.T) {
508526
}
509527
},
510528
wantOut: heredoc.Doc(`
511-
Failed • fix something • OWNER/REPO#101
529+
Failed • session one
512530
Started on behalf of octocat about 6 hours ago
513531
Used 1.5 premium request(s)
514532
533+
OWNER/REPO#101 • fix something
534+
515535
X blah blah
516536
https://github.com/OWNER/REPO/actions/runs/9999
517537
@@ -696,6 +716,7 @@ func Test_viewRun(t *testing.T) {
696716
return &capi.Session{
697717
ID: "some-session-id",
698718
State: "completed",
719+
Name: "session one",
699720
CreatedAt: sampleDate,
700721
CompletedAt: sampleCompletedAt,
701722
PremiumRequests: 1.5,
@@ -714,10 +735,12 @@ func Test_viewRun(t *testing.T) {
714735
}
715736
},
716737
wantOut: heredoc.Doc(`
717-
Ready for review • fix something • OWNER/REPO#101
738+
Ready for review • session one
718739
Started on behalf of octocat about 6 hours ago
719740
Used 1.5 premium request(s) • Duration 5m0s
720741
742+
OWNER/REPO#101 • fix something
743+
721744
For detailed session logs, try:
722745
gh agent-task view 'some-session-id' --log
723746
@@ -799,10 +822,12 @@ func Test_viewRun(t *testing.T) {
799822
)
800823
},
801824
wantOut: heredoc.Doc(`
802-
Ready for review • fix something • OWNER/REPO#101
825+
Ready for review • session one
803826
Started on behalf of octocat about 6 hours ago
804827
Used 1.5 premium request(s) • Duration 5m0s
805828
829+
OWNER/REPO#101 • fix something
830+
806831
For detailed session logs, try:
807832
gh agent-task view 'some-session-id' --log
808833
@@ -886,10 +911,12 @@ func Test_viewRun(t *testing.T) {
886911
)
887912
},
888913
wantOut: heredoc.Doc(`
889-
Ready for review • fix something • OWNER/REPO#101
914+
Ready for review • session one
890915
Started on behalf of octocat about 6 hours ago
891916
Used 1.5 premium request(s) • Duration 5m0s
892917
918+
OWNER/REPO#101 • fix something
919+
893920
For detailed session logs, try:
894921
gh agent-task view 'some-session-id' --log
895922

0 commit comments

Comments
 (0)