| 328 | } |
| 329 | |
| 330 | func getExtensions(opts ExtBrowseOpts) ([]extEntry, error) { |
| 331 | extEntries := []extEntry{} |
| 332 | |
| 333 | installed := opts.Em.List() |
| 334 | |
| 335 | result, err := opts.Searcher.Repositories(search.Query{ |
| 336 | Kind: search.KindRepositories, |
| 337 | Limit: 1000, |
| 338 | Qualifiers: search.Qualifiers{ |
| 339 | Topic: []string{"gh-extension"}, |
| 340 | }, |
| 341 | }) |
| 342 | if err != nil { |
| 343 | return extEntries, fmt.Errorf("failed to search for extensions: %w", err) |
| 344 | } |
| 345 | |
| 346 | host, _ := opts.Cfg.Authentication().DefaultHost() |
| 347 | |
| 348 | for _, repo := range result.Items { |
| 349 | if !strings.HasPrefix(repo.Name, "gh-") { |
| 350 | continue |
| 351 | } |
| 352 | ee := extEntry{ |
| 353 | URL: "https://" + host + "/" + repo.FullName, |
| 354 | FullName: repo.FullName, |
| 355 | Name: repo.Name, |
| 356 | description: repo.Description, |
| 357 | } |
| 358 | for _, v := range installed { |
| 359 | // TODO consider a Repo() on Extension interface |
| 360 | var installedRepo string |
| 361 | if u, err := git.ParseURL(v.URL()); err == nil { |
| 362 | if r, err := ghrepo.FromURL(u); err == nil { |
| 363 | installedRepo = ghrepo.FullName(r) |
| 364 | } |
| 365 | } |
| 366 | if repo.FullName == installedRepo { |
| 367 | ee.Installed = true |
| 368 | } |
| 369 | } |
| 370 | if repo.Owner.Login == "cli" || repo.Owner.Login == "github" { |
| 371 | ee.Official = true |
| 372 | } |
| 373 | |
| 374 | extEntries = append(extEntries, ee) |
| 375 | } |
| 376 | |
| 377 | return extEntries, nil |
| 378 | } |
| 379 | |
| 380 | func ExtBrowse(opts ExtBrowseOpts) error { |
| 381 | if opts.Debug { |