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

Function viewRun

pkg/cmd/discussion/view/view.go:237–339  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

235}
236
237func viewRun(opts *ViewOptions) error {
238 repo, err := opts.BaseRepo()
239 if err != nil {
240 return err
241 }
242
243 c, err := opts.Client()
244 if err != nil {
245 return err
246 }
247
248 repliesMode := opts.CommentNodeID != "" || opts.CommentDatabaseID != 0
249
250 if opts.WebMode {
251 if !repliesMode {
252 openURL := ghrepo.GenerateRepoURL(repo, "discussions/%d", opts.DiscussionNumber)
253 if opts.IO.IsStderrTTY() {
254 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
255 }
256 return opts.Browser.Browse(openURL)
257 }
258
259 opts.IO.StartProgressIndicator()
260 commentID, err := resolveCommentNodeID(c, repo, opts)
261 if err != nil {
262 opts.IO.StopProgressIndicator()
263 return err
264 }
265 comment, err := c.GetComment(repo.RepoHost(), commentID)
266 opts.IO.StopProgressIndicator()
267 if err != nil {
268 return err
269 }
270 if opts.IO.IsStderrTTY() {
271 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(comment.URL))
272 }
273 return opts.Browser.Browse(comment.URL)
274 }
275
276 opts.IO.DetectTerminalTheme()
277 opts.IO.StartProgressIndicator()
278
279 if repliesMode {
280 commentID, err := resolveCommentNodeID(c, repo, opts)
281 if err != nil {
282 opts.IO.StopProgressIndicator()
283 return err
284 }
285
286 discussion, err := c.GetCommentReplies(repo.RepoHost(), commentID, opts.Limit, opts.After, opts.Order == orderNewest)
287 opts.IO.StopProgressIndicator()
288 if err != nil {
289 return err
290 }
291
292 if opts.Exporter != nil {
293 return opts.Exporter.Write(opts.IO, discussion)
294 }

Callers 2

TestViewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
resolveCommentNodeIDFunction · 0.85
printRawRepliesFunction · 0.85
needsCommentsFunction · 0.85
printHumanViewFunction · 0.85
printRawCommentsFunction · 0.85
printRawViewFunction · 0.85
IsStderrTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
StartPagerMethod · 0.80

Tested by 1

TestViewRunFunction · 0.56