MCPcopy Index your code
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/repo/list/list.go:119–217  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

117var defaultFields = []string{"nameWithOwner", "description", "isPrivate", "isFork", "isArchived", "createdAt", "pushedAt"}
118
119func listRun(opts *ListOptions) error {
120 httpClient, err := opts.HttpClient()
121 if err != nil {
122 return err
123 }
124
125 cfg, err := opts.Config()
126 if err != nil {
127 return err
128 }
129
130 host, _ := cfg.Authentication().DefaultHost()
131
132 if opts.Detector == nil {
133 cachedClient := api.NewCachedHTTPClient(httpClient, time.Hour*24)
134 opts.Detector = fd.NewDetector(cachedClient, host)
135 }
136 features, err := opts.Detector.RepositoryFeatures()
137 if err != nil {
138 return err
139 }
140
141 fields := defaultFields
142 // TODO repoFeaturesCleanup
143 if features.VisibilityField {
144 fields = append(defaultFields, "visibility")
145 }
146
147 filter := FilterOptions{
148 Visibility: opts.Visibility,
149 Fork: opts.Fork,
150 Source: opts.Source,
151 Language: opts.Language,
152 Topic: opts.Topic,
153 Archived: opts.Archived,
154 NonArchived: opts.NonArchived,
155 Fields: fields,
156 }
157 if opts.Exporter != nil {
158 filter.Fields = opts.Exporter.Fields()
159 }
160
161 listResult, err := listRepos(httpClient, host, opts.Limit, opts.Owner, filter)
162 if err != nil {
163 return err
164 }
165
166 if opts.Owner != "" && listResult.Owner == "" && !listResult.FromSearch {
167 return fmt.Errorf("the owner handle %q was not recognized as either a GitHub user or an organization", opts.Owner)
168 }
169
170 if err := opts.IO.StartPager(); err != nil {
171 fmt.Fprintf(opts.IO.ErrOut, "error starting pager: %v\n", err)
172 }
173 defer opts.IO.StopPager()
174
175 if opts.Exporter != nil {
176 return opts.Exporter.Write(opts.IO, listResult.Repositories)

Callers 5

TestRepoList_nonttyFunction · 0.70
TestRepoList_ttyFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

NewCachedHTTPClientFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
listReposFunction · 0.85
StartPagerMethod · 0.80
StopPagerMethod · 0.80
ColorSchemeMethod · 0.80
AddTimeFieldMethod · 0.80
IsStdoutTTYMethod · 0.80
repoInfoFunction · 0.70
listHeaderFunction · 0.70

Tested by 4

TestRepoList_nonttyFunction · 0.56
TestRepoList_ttyFunction · 0.56