MCPcopy
hub / github.com/cli/cli / openInBrowser

Function openInBrowser

pkg/cmd/discussion/list/list.go:268–303  ·  view source on GitHub ↗
(opts *ListOptions, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

266}
267
268func openInBrowser(opts *ListOptions, repo ghrepo.Interface) error {
269 discussionsURL := ghrepo.GenerateRepoURL(repo, "discussions")
270
271 var queryParts []string
272 if opts.Search != "" {
273 queryParts = append(queryParts, opts.Search)
274 }
275 if opts.State != "" && opts.State != stateAll {
276 queryParts = append(queryParts, "is:"+opts.State)
277 }
278 if opts.Author != "" {
279 queryParts = append(queryParts, fmt.Sprintf("author:%q", opts.Author))
280 }
281 for _, l := range opts.Labels {
282 queryParts = append(queryParts, fmt.Sprintf("label:%q", l))
283 }
284 if opts.Category != "" {
285 queryParts = append(queryParts, fmt.Sprintf("category:%q", opts.Category))
286 }
287 if opts.Answered != nil {
288 if *opts.Answered {
289 queryParts = append(queryParts, "is:answered")
290 } else {
291 queryParts = append(queryParts, "is:unanswered")
292 }
293 }
294
295 if len(queryParts) > 0 {
296 discussionsURL += "?" + url.Values{"q": {strings.Join(queryParts, " ")}}.Encode()
297 }
298
299 if opts.IO.IsStderrTTY() {
300 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(discussionsURL))
301 }
302 return opts.Browser.Browse(discussionsURL)
303}
304
305func listHeader(repoName string, count, total int, state string) string {
306 switch state {

Callers 1

listRunFunction · 0.85

Calls 5

GenerateRepoURLFunction · 0.92
DisplayURLFunction · 0.92
JoinMethod · 0.80
IsStderrTTYMethod · 0.80
BrowseMethod · 0.65

Tested by

no test coverage detected