| 60 | } |
| 61 | |
| 62 | func getExtensions(opts ExtBrowseOpts) ([]extEntry, error) { |
| 63 | extEntries := []extEntry{} |
| 64 | |
| 65 | installed := opts.Em.List() |
| 66 | |
| 67 | result, err := opts.Searcher.Repositories(search.Query{ |
| 68 | Kind: search.KindRepositories, |
| 69 | Limit: 1000, |
| 70 | Qualifiers: search.Qualifiers{ |
| 71 | Topic: []string{"gh-extension"}, |
| 72 | }, |
| 73 | }) |
| 74 | if err != nil { |
| 75 | return extEntries, fmt.Errorf("failed to search for extensions: %w", err) |
| 76 | } |
| 77 | |
| 78 | host, _ := opts.Cfg.Authentication().DefaultHost() |
| 79 | |
| 80 | for _, repo := range result.Items { |
| 81 | if !strings.HasPrefix(repo.Name, "gh-") { |
| 82 | continue |
| 83 | } |
| 84 | ee := extEntry{ |
| 85 | URL: "https://" + host + "/" + repo.FullName, |
| 86 | FullName: repo.FullName, |
| 87 | Name: repo.Name, |
| 88 | description: repo.Description, |
| 89 | } |
| 90 | for _, installedExtension := range installed { |
| 91 | var installedRepo string |
| 92 | if u, err := git.ParseURL(installedExtension.URL()); err == nil { |
| 93 | if r, err := ghrepo.FromURL(u); err == nil { |
| 94 | installedRepo = ghrepo.FullName(r) |
| 95 | } |
| 96 | } |
| 97 | if repo.FullName == installedRepo { |
| 98 | ee.Installed = true |
| 99 | } |
| 100 | } |
| 101 | if repo.Owner.Login == "cli" || repo.Owner.Login == "github" { |
| 102 | ee.Official = true |
| 103 | } |
| 104 | |
| 105 | extEntries = append(extEntries, ee) |
| 106 | } |
| 107 | |
| 108 | return extEntries, nil |
| 109 | } |
| 110 | |
| 111 | func ExtBrowse(opts ExtBrowseOpts) error { |
| 112 | if opts.Debug { |