| 185 | } |
| 186 | |
| 187 | func 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 | |
| 230 | func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error) { |
| 231 | if opts.ProjectsFlag { |