MCPcopy
hub / github.com/cli/cli / getExtensions

Function getExtensions

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

Source from the content-addressed store, hash-verified

328}
329
330func 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
380func ExtBrowse(opts ExtBrowseOpts) error {
381 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