MCPcopy
hub / github.com/cli/cli / printSession

Function printSession

pkg/cmd/agent-task/view/view.go:303–368  ·  view source on GitHub ↗
(opts *ViewOptions, session *capi.Session)

Source from the content-addressed store, hash-verified

301}
302
303func printSession(opts *ViewOptions, session *capi.Session) {
304 cs := opts.IO.ColorScheme()
305
306 fmt.Fprintf(opts.IO.Out, "%s • %s\n",
307 shared.ColorFuncForSessionState(*session, cs)(shared.SessionStateString(session.State)),
308 cs.Bold(session.Name),
309 )
310
311 if session.User != nil {
312 fmt.Fprintf(opts.IO.Out, "Started on behalf of %s %s\n", session.User.Login, text.FuzzyAgo(time.Now(), session.CreatedAt))
313 } else {
314 // Should never happen, but we need to cover the path
315 fmt.Fprintf(opts.IO.Out, "Started %s\n", text.FuzzyAgo(time.Now(), session.CreatedAt))
316 }
317
318 usedPremiumRequests := strings.TrimSuffix(fmt.Sprintf("%.1f", session.PremiumRequests), ".0")
319 usedPremiumRequestsNote := fmt.Sprintf("Used %s premium request(s)", usedPremiumRequests)
320
321 var durationNote string
322 if session.CompletedAt.After(session.CreatedAt) {
323 durationNote = fmt.Sprintf(" • Duration %s", session.CompletedAt.Sub(session.CreatedAt).Round(time.Second).String())
324 }
325
326 fmt.Fprintf(opts.IO.Out, "%s%s\n", cs.Muted(usedPremiumRequestsNote), cs.Muted(durationNote))
327
328 // Note that when the session is just created, a PR is not yet available for it.
329 if session.PullRequest != nil {
330 fmt.Fprintf(opts.IO.Out, "\n%s%s • %s\n",
331 session.PullRequest.Repository.NameWithOwner,
332 cs.ColorFromString(prShared.ColorForPRState(*session.PullRequest))(fmt.Sprintf("#%d", session.PullRequest.Number)),
333 cs.Bold(session.PullRequest.Title),
334 )
335 }
336
337 if session.Error != nil {
338 var workflowRunURL string
339 if session.WorkflowRunID != 0 && session.PullRequest != nil {
340 if u, err := url.Parse(session.PullRequest.URL); err == nil {
341 workflowRunURL = fmt.Sprintf("%s://%s/%s/actions/runs/%d", u.Scheme, u.Host, session.PullRequest.Repository.NameWithOwner, session.WorkflowRunID)
342 }
343 }
344
345 message := session.Error.Message
346 if message == "" {
347 message = "An error occurred"
348 }
349 fmt.Fprintf(opts.IO.Out, "\n%s %s\n", cs.FailureIconWithColor(cs.Red), message)
350
351 if workflowRunURL != "" {
352 // We don't need to prefix the link with any text (e.g. "checkout the logs here")
353 // because the error message already contains all the information.
354 fmt.Fprintf(opts.IO.Out, "%s\n", workflowRunURL)
355 }
356 }
357
358 if !opts.Log {
359 fmt.Fprint(opts.IO.Out, cs.Mutedf("\nFor detailed session logs, try:\ngh agent-task view '%s' --log\n", session.ID))
360 } else if !opts.Follow {

Callers 1

viewRunFunction · 0.85

Calls 8

FuzzyAgoFunction · 0.92
ColorSchemeMethod · 0.80
BoldMethod · 0.80
MutedMethod · 0.80
ColorFromStringMethod · 0.80
FailureIconWithColorMethod · 0.80
MutedfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected