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

Function viewRun

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

Source from the content-addressed store, hash-verified

109}
110
111func viewRun(opts *ViewOptions) error {
112 findOptions := shared.FindOptions{
113 Selector: opts.SelectorArg,
114 Fields: defaultFields,
115 Detector: opts.Detector,
116 }
117 if opts.BrowserMode {
118 findOptions.Fields = []string{"url"}
119 } else if opts.Exporter != nil {
120 findOptions.Fields = opts.Exporter.Fields()
121 // The agent hint is skipped for merged or closed pull requests, which needs the state even when it was not
122 // requested. The exporter still writes only the requested fields.
123 if opts.InvokingAgent != "" && !slices.Contains(findOptions.Fields, "state") {
124 findOptions.Fields = slices.Concat(findOptions.Fields, []string{"state"})
125 }
126 }
127 pr, baseRepo, err := opts.Finder.Find(findOptions)
128 if err != nil {
129 return err
130 }
131
132 connectedToTerminal := opts.IO.IsStdoutTTY()
133
134 if opts.BrowserMode {
135 openURL := pr.URL
136 if connectedToTerminal {
137 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
138 }
139 return opts.Browser.Browse(openURL)
140 }
141
142 printEventListenHint(opts, baseRepo, pr)
143
144 opts.IO.DetectTerminalTheme()
145 if err := opts.IO.StartPager(); err == nil {
146 defer opts.IO.StopPager()
147 } else {
148 fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err)
149 }
150
151 if opts.Exporter != nil {
152 return opts.Exporter.Write(opts.IO, pr)
153 }
154
155 if connectedToTerminal {
156 return printHumanPrPreview(opts, baseRepo, pr)
157 }
158
159 if opts.Comments {
160 fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.DisplayableReviews()))
161 return nil
162 }
163
164 return printRawPrPreview(opts.IO, pr)
165}
166
167func printRawPrPreview(io *iostreams.IOStreams, pr *api.PullRequest) error {
168 out := io.Out

Callers 4

NewCmdViewFunction · 0.70

Calls 15

DisplayURLFunction · 0.92
RawCommentListFunction · 0.92
printHumanPrPreviewFunction · 0.85
printRawPrPreviewFunction · 0.85
ContainsMethod · 0.80
IsStdoutTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
DisplayableReviewsMethod · 0.80
printEventListenHintFunction · 0.70
FieldsMethod · 0.65

Tested by 3