MCPcopy Create free account
hub / github.com/cli/cli / viewRun

Function viewRun

pkg/cmd/pr/view/view.go:97–144  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

95}
96
97func viewRun(opts *ViewOptions) error {
98 findOptions := shared.FindOptions{
99 Selector: opts.SelectorArg,
100 Fields: defaultFields,
101 Detector: opts.Detector,
102 }
103 if opts.BrowserMode {
104 findOptions.Fields = []string{"url"}
105 } else if opts.Exporter != nil {
106 findOptions.Fields = opts.Exporter.Fields()
107 }
108 pr, baseRepo, err := opts.Finder.Find(findOptions)
109 if err != nil {
110 return err
111 }
112
113 connectedToTerminal := opts.IO.IsStdoutTTY()
114
115 if opts.BrowserMode {
116 openURL := pr.URL
117 if connectedToTerminal {
118 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
119 }
120 return opts.Browser.Browse(openURL)
121 }
122
123 opts.IO.DetectTerminalTheme()
124 if err := opts.IO.StartPager(); err == nil {
125 defer opts.IO.StopPager()
126 } else {
127 fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err)
128 }
129
130 if opts.Exporter != nil {
131 return opts.Exporter.Write(opts.IO, pr)
132 }
133
134 if connectedToTerminal {
135 return printHumanPrPreview(opts, baseRepo, pr)
136 }
137
138 if opts.Comments {
139 fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.DisplayableReviews()))
140 return nil
141 }
142
143 return printRawPrPreview(opts.IO, pr)
144}
145
146func printRawPrPreview(io *iostreams.IOStreams, pr *api.PullRequest) error {
147 out := io.Out

Callers 2

NewCmdViewFunction · 0.70

Calls 13

DisplayURLFunction · 0.92
RawCommentListFunction · 0.92
printHumanPrPreviewFunction · 0.85
printRawPrPreviewFunction · 0.85
IsStdoutTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
DisplayableReviewsMethod · 0.80
FieldsMethod · 0.65
FindMethod · 0.65
BrowseMethod · 0.65

Tested by 1