in commands/mr/view/mr_view.go [160:263]
func printTTYMRPreview(opts *ViewOpts, mr *gitlab.MergeRequest, mrApprovals *gitlab.MergeRequestApprovalState, notes []*gitlab.Note) error {
c := opts.IO.Color()
out := opts.IO.StdOut
mrTimeAgo := utils.TimeToPrettyTimeAgo(*mr.CreatedAt)
// Header
fmt.Fprint(out, mrState(c, mr))
fmt.Fprintf(out, c.Gray(" • opened by %s %s\n"), mr.Author.Username, mrTimeAgo)
fmt.Fprint(out, mr.Title)
fmt.Fprintf(out, c.Gray(" !%d"), mr.IID)
fmt.Fprintln(out)
// Description
if mr.Description != "" {
mr.Description, _ = utils.RenderMarkdown(mr.Description, opts.IO.BackgroundColor())
fmt.Fprintln(out, mr.Description)
}
fmt.Fprintf(out, c.Gray("\n%d upvotes • %d downvotes • %d comments\n"), mr.Upvotes, mr.Downvotes, mr.UserNotesCount)
// Meta information
if labels := labelsList(mr); labels != "" {
fmt.Fprint(out, c.Bold("Labels: "))
fmt.Fprintln(out, labels)
}
if assignees := assigneesList(mr); assignees != "" {
fmt.Fprint(out, c.Bold("Assignees: "))
fmt.Fprintln(out, assignees)
}
if reviewers := reviewersList(mr); reviewers != "" {
fmt.Fprint(out, c.Bold("Reviewers: "))
fmt.Fprintln(out, reviewers)
}
if mr.Milestone != nil {
fmt.Fprint(out, c.Bold("Milestone: "))
fmt.Fprintln(out, mr.Milestone.Title)
}
if mr.State == "closed" {
fmt.Fprintf(out, "Closed by: %s %s\n", mr.ClosedBy.Username, mrTimeAgo)
}
if mr.Pipeline != nil {
fmt.Fprint(out, c.Bold("Pipeline status: "))
var status string
switch s := mr.Pipeline.Status; s {
case "failed":
status = c.Red(s)
case "success":
status = c.Green(s)
default:
status = c.Gray(s)
}
fmt.Fprintf(out, "%s (View pipeline with `%s`)\n", status, c.Bold("glab ci view "+mr.SourceBranch))
if mr.MergeWhenPipelineSucceeds && mr.Pipeline.Status != "success" {
fmt.Fprintf(out, "%s Requires pipeline to succeed before merging.\n", c.WarnIcon())
}
}
if mrApprovals != nil {
fmt.Fprintln(out, c.Bold("Approvals status:"))
mrutils.PrintMRApprovalState(opts.IO, mrApprovals)
}
fmt.Fprintf(out, "%s This merge request has %s changes.\n", c.GreenCheck(), c.Yellow(mr.ChangesCount))
if mr.State == "merged" && mr.MergedBy != nil { //nolint:staticcheck
fmt.Fprintf(out, "%s The changes were merged into %s by %s %s.\n", c.GreenCheck(), mr.TargetBranch, mr.MergedBy.Name, utils.TimeToPrettyTimeAgo(*mr.MergedAt)) //nolint:staticcheck
}
if mr.HasConflicts {
fmt.Fprintf(out, c.Red("%s This branch has conflicts that must be resolved.\n"), c.FailedIcon())
}
// Comments
if opts.ShowComments {
fmt.Fprintln(out, heredoc.Doc(`
--------------------------------------------
Comments / Notes
--------------------------------------------
`))
if len(notes) > 0 {
for _, note := range notes {
if note.System && !opts.ShowSystemLogs {
continue
}
createdAt := utils.TimeToPrettyTimeAgo(*note.CreatedAt)
fmt.Fprint(out, note.Author.Username)
if note.System {
fmt.Fprintf(out, " %s ", note.Body)
fmt.Fprintln(out, c.Gray(createdAt))
} else {
body, _ := utils.RenderMarkdown(note.Body, opts.IO.BackgroundColor())
fmt.Fprint(out, " commented ")
fmt.Fprintf(out, c.Gray("%s\n"), createdAt)
fmt.Fprintln(out, utils.Indent(body, " "))
}
fmt.Fprintln(out)
}
} else {
fmt.Fprintln(out, "This merge request has no comments.")
}
}
fmt.Fprintln(out)
fmt.Fprintf(out, c.Gray("View this merge request on GitLab: %s\n"), mr.WebURL)
return nil
}