MCPcopy Create free account
hub / github.com/cli/cli / getExtensions

Function getExtensions

pkg/cmd/extension/browse/browse.go:324–372  ·  view source on GitHub ↗
(opts ExtBrowseOpts)

Source from the content-addressed store, hash-verified

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

Callers 2

ExtBrowseFunction · 0.85
Test_getExtensionReposFunction · 0.85

Calls 9

ParseURLFunction · 0.92
FromURLFunction · 0.92
FullNameFunction · 0.92
ListMethod · 0.65
RepositoriesMethod · 0.65
ErrorfMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65
URLMethod · 0.65

Tested by 1

Test_getExtensionReposFunction · 0.68