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

Function viewRun

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

Source from the content-addressed store, hash-verified

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

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