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

Function viewRun

pkg/cmd/issue/artifact/view/view.go:113–162  ·  view source on GitHub ↗
(opts *ViewOptions)

Source from the content-addressed store, hash-verified

111}
112
113func viewRun(opts *ViewOptions) error {
114 repo, err := opts.BaseRepo()
115 if err != nil {
116 return err
117 }
118 if err := shared.CheckHost(repo.RepoHost()); err != nil {
119 return err
120 }
121
122 c, err := opts.Client()
123 if err != nil {
124 return err
125 }
126 if err := shared.CheckIssue(c, repo, opts.IssueNumber); err != nil {
127 return err
128 }
129
130 artifact, err := c.Get(repo, opts.IssueNumber, opts.ArtifactNumber)
131 if err != nil {
132 return err
133 }
134 if err := shared.CheckType(artifact.Artifact); err != nil {
135 return err
136 }
137 viewing, err := shared.FindVersion(artifact, opts.Version)
138 if err != nil {
139 return err
140 }
141
142 if opts.WebMode {
143 return openInBrowser(opts, artifact.Artifact)
144 }
145
146 if opts.Exporter != nil {
147 return opts.Exporter.Write(opts.IO, artifact)
148 }
149
150 if !opts.IO.IsStdoutTTY() {
151 printRawArtifact(opts.IO.Out, artifact, viewing)
152 return nil
153 }
154
155 opts.IO.DetectTerminalTheme()
156 if err := opts.IO.StartPager(); err != nil {
157 fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err)
158 }
159 defer opts.IO.StopPager()
160
161 return printHumanArtifact(opts, repo, artifact, viewing)
162}
163
164// openInBrowser opens a document's page on GitHub, or a link's URL. The page
165// comes from the API, so the message shows it like gh issue view --web does.

Callers 2

TestViewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

CheckHostFunction · 0.92
CheckIssueFunction · 0.92
CheckTypeFunction · 0.92
FindVersionFunction · 0.92
printRawArtifactFunction · 0.85
printHumanArtifactFunction · 0.85
IsStdoutTTYMethod · 0.80
DetectTerminalThemeMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
openInBrowserFunction · 0.70
BaseRepoMethod · 0.65

Tested by 1

TestViewRunFunction · 0.56