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

Function openInBrowser

pkg/cmd/issue/artifact/view/view.go:169–183  ·  view source on GitHub ↗

openInBrowser opens a document's page on GitHub, or a link's URL. The page comes from the API, so the message shows it like gh issue view --web does. A link's URL is anything its author saved, so only an http(s) URL opens, and the message shows the whole URL, where text.DisplayURL would hide its por

(opts *ViewOptions, a client.Artifact)

Source from the content-addressed store, hash-verified

167// and the message shows the whole URL, where text.DisplayURL would hide its
168// port, query and fragment.
169func openInBrowser(opts *ViewOptions, a client.Artifact) error {
170 target, shown := a.URL, text.DisplayURL(a.URL)
171 if a.Type == client.TypeLink {
172 u, ok := shared.HTTPURL(a.Body)
173 if !ok {
174 return fmt.Errorf("artifact %d doesn't link to an http(s) URL; `--web` only opens http(s) URLs", a.Number)
175 }
176 target, shown = u, u
177 }
178
179 if opts.IO.IsStdoutTTY() {
180 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", shown)
181 }
182 return opts.Browser.Browse(target)
183}
184
185// printRawArtifact prints key lines in a fixed order, then the body after a
186// "--" line, like gh issue view. Null values print as empty fields, so every

Callers 1

viewRunFunction · 0.70

Calls 5

DisplayURLFunction · 0.92
HTTPURLFunction · 0.92
IsStdoutTTYMethod · 0.80
ErrorfMethod · 0.65
BrowseMethod · 0.65

Tested by

no test coverage detected