MCPcopy
hub / github.com/cli/cli / runBrowse

Function runBrowse

pkg/cmd/browse/browse.go:187–228  ·  view source on GitHub ↗
(opts *BrowseOptions)

Source from the content-addressed store, hash-verified

185}
186
187func runBrowse(opts *BrowseOptions) error {
188 baseRepo, err := opts.BaseRepo()
189 if err != nil {
190 return fmt.Errorf("unable to determine base repository: %w", err)
191 }
192
193 if opts.Commit != "" && opts.Commit == emptyCommitFlag {
194 commit, err := opts.GitClient.LastCommit()
195 if err != nil {
196 return err
197 }
198 opts.Commit = commit.Sha
199 }
200
201 section, err := parseSection(baseRepo, opts)
202 if err != nil {
203 return err
204 }
205 url := ghrepo.GenerateRepoURL(baseRepo, "%s", section)
206
207 if opts.NoBrowserFlag {
208 client, err := opts.HttpClient()
209 if err != nil {
210 return err
211 }
212
213 exist, err := api.RepoExists(api.NewClientFromHTTP(client), baseRepo)
214 if err != nil {
215 return err
216 }
217 if !exist {
218 return fmt.Errorf("%s doesn't exist", text.DisplayURL(url))
219 }
220 _, err = fmt.Fprintln(opts.IO.Out, url)
221 return err
222 }
223
224 if opts.IO.IsStdoutTTY() {
225 fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", text.DisplayURL(url))
226 }
227 return opts.Browser.Browse(url)
228}
229
230func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error) {
231 if opts.ProjectsFlag {

Callers 2

NewCmdBrowseFunction · 0.85
Test_runBrowseFunction · 0.85

Calls 10

GenerateRepoURLFunction · 0.92
RepoExistsFunction · 0.92
NewClientFromHTTPFunction · 0.92
DisplayURLFunction · 0.92
parseSectionFunction · 0.85
IsStdoutTTYMethod · 0.80
BaseRepoMethod · 0.65
ErrorfMethod · 0.65
LastCommitMethod · 0.65
BrowseMethod · 0.65

Tested by 1

Test_runBrowseFunction · 0.68