fix(agent-task view): improve session overview

Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
Babak K. Shandiz 2025-09-19 17:37:07 +01:00
parent 3e43a98814
commit ecfbb67e99
No known key found for this signature in database
GPG key ID: 9472CAEFF56C742E
2 changed files with 53 additions and 24 deletions

View file

@ -296,17 +296,10 @@ func viewRun(opts *ViewOptions) error {
func printSession(opts *ViewOptions, session *capi.Session) {
cs := opts.IO.ColorScheme()
if session.PullRequest != nil {
fmt.Fprintf(opts.IO.Out, "%s • %s • %s%s\n",
shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)),
cs.Bold(session.PullRequest.Title),
session.PullRequest.Repository.NameWithOwner,
cs.ColorFromString(prShared.ColorForPRState(*session.PullRequest))(fmt.Sprintf("#%d", session.PullRequest.Number)),
)
} else {
// This can happen when the session is just created and a PR is not yet available for it
fmt.Fprintf(opts.IO.Out, "%s\n", shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)))
}
fmt.Fprintf(opts.IO.Out, "%s • %s\n",
shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)),
cs.Bold(session.Name),
)
if session.User != nil {
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) {
fmt.Fprintf(opts.IO.Out, "%s%s\n", cs.Muted(usedPremiumRequestsNote), cs.Muted(durationNote))
// Note that when the session is just created, a PR is not yet available for it.
if session.PullRequest != nil {
fmt.Fprintf(opts.IO.Out, "\n%s%s • %s\n",
session.PullRequest.Repository.NameWithOwner,
cs.ColorFromString(prShared.ColorForPRState(*session.PullRequest))(fmt.Sprintf("#%d", session.PullRequest.Number)),
cs.Bold(session.PullRequest.Title),
)
}
if session.Error != nil {
var workflowRunURL string
if session.WorkflowRunID != 0 && session.PullRequest != nil {
@ -347,9 +349,9 @@ func printSession(opts *ViewOptions, session *capi.Session) {
}
if !opts.Log {
fmt.Fprintf(opts.IO.Out, "\nFor detailed session logs, try:\ngh agent-task view '%s' --log\n", session.ID)
fmt.Fprint(opts.IO.Out, cs.Mutedf("\nFor detailed session logs, try:\ngh agent-task view '%s' --log\n", session.ID))
} else if !opts.Follow {
fmt.Fprintf(opts.IO.Out, "\nTo follow session logs, try:\ngh agent-task view '%s' --log --follow\n", session.ID)
fmt.Fprint(opts.IO.Out, cs.Mutedf("\nTo follow session logs, try:\ngh agent-task view '%s' --log --follow\n", session.ID))
}
if session.PullRequest != nil {

View file

@ -215,6 +215,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "completed",
Name: "session one",
CreatedAt: sampleDate,
CompletedAt: sampleCompletedAt,
PremiumRequests: 1.5,
@ -233,10 +234,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Ready for review fix something OWNER/REPO#101
Ready for review session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log
@ -258,6 +261,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "completed",
Name: "session one",
CreatedAt: sampleDate,
CompletedAt: sampleCompletedAt,
PremiumRequests: 1.5,
@ -273,10 +277,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Ready for review fix something OWNER/REPO#101
Ready for review session one
Started about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log
@ -298,6 +304,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "completed",
Name: "session one",
CreatedAt: sampleDate,
CompletedAt: sampleCompletedAt,
PremiumRequests: 1.5,
@ -308,7 +315,7 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Ready for review
Ready for review session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
@ -330,6 +337,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "completed",
Name: "session one",
CreatedAt: sampleDate,
CompletedAt: sampleCompletedAt,
PremiumRequests: 1.5,
@ -337,7 +345,7 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Ready for review
Ready for review session one
Started about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
@ -358,6 +366,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "completed",
Name: "session one",
CreatedAt: sampleDate,
CompletedAt: sampleCompletedAt,
PremiumRequests: 0,
@ -376,10 +385,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Ready for review fix something OWNER/REPO#101
Ready for review session one
Started on behalf of octocat about 6 hours ago
Used 0 premium request(s) Duration 5m0s
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log
@ -400,6 +411,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "in_progress",
Name: "session one",
CreatedAt: sampleDate,
PremiumRequests: 1.5,
PullRequest: &api.PullRequest{
@ -417,10 +429,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
In progress fix something OWNER/REPO#101
In progress session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s)
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log
@ -441,6 +455,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "failed",
Name: "session one",
CreatedAt: sampleDate,
PremiumRequests: 1.5,
Error: &capi.SessionError{
@ -461,10 +476,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Failed fix something OWNER/REPO#101
Failed session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s)
OWNER/REPO#101 fix something
X blah blah
For detailed session logs, try:
@ -487,6 +504,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "failed",
Name: "session one",
CreatedAt: sampleDate,
PremiumRequests: 1.5,
WorkflowRunID: 9999,
@ -508,10 +526,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Failed fix something OWNER/REPO#101
Failed session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s)
OWNER/REPO#101 fix something
X blah blah
https://github.com/OWNER/REPO/actions/runs/9999
@ -696,6 +716,7 @@ func Test_viewRun(t *testing.T) {
return &capi.Session{
ID: "some-session-id",
State: "completed",
Name: "session one",
CreatedAt: sampleDate,
CompletedAt: sampleCompletedAt,
PremiumRequests: 1.5,
@ -714,10 +735,12 @@ func Test_viewRun(t *testing.T) {
}
},
wantOut: heredoc.Doc(`
Ready for review fix something OWNER/REPO#101
Ready for review session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log
@ -799,10 +822,12 @@ func Test_viewRun(t *testing.T) {
)
},
wantOut: heredoc.Doc(`
Ready for review fix something OWNER/REPO#101
Ready for review session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log
@ -886,10 +911,12 @@ func Test_viewRun(t *testing.T) {
)
},
wantOut: heredoc.Doc(`
Ready for review fix something OWNER/REPO#101
Ready for review session one
Started on behalf of octocat about 6 hours ago
Used 1.5 premium request(s) Duration 5m0s
OWNER/REPO#101 fix something
For detailed session logs, try:
gh agent-task view 'some-session-id' --log