MCPcopy
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/discussion/list/list.go:189–266  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

187}
188
189func listRun(opts *ListOptions) error {
190 repo, err := opts.BaseRepo()
191 if err != nil {
192 return err
193 }
194
195 if opts.WebMode {
196 return openInBrowser(opts, repo)
197 }
198
199 dc, err := opts.Client()
200 if err != nil {
201 return err
202 }
203
204 var categoryID string
205 var categorySlug string
206 if opts.Category != "" {
207 categories, err := dc.ListCategories(repo)
208 if err != nil {
209 return err
210 }
211 cat, err := shared.MatchCategory(opts.Category, categories)
212 if err != nil {
213 return err
214 }
215 categoryID = cat.ID
216 categorySlug = cat.Slug
217 }
218
219 state := toFilterState(opts.State)
220 orderBy, direction := toOrderByAndDirection(opts.Sort, opts.Order)
221
222 var result *client.DiscussionListResult
223
224 useSearch := opts.Author != "" || len(opts.Labels) > 0 || opts.Search != ""
225 if useSearch {
226 filters := client.SearchFilters{
227 Author: opts.Author,
228 Labels: opts.Labels,
229 State: state,
230 Category: categorySlug,
231 Answered: opts.Answered,
232 Keywords: opts.Search,
233 OrderBy: orderBy,
234 Direction: direction,
235 }
236 result, err = dc.Search(repo, filters, opts.After, opts.Limit)
237 } else {
238 filters := client.ListFilters{
239 State: state,
240 CategoryID: categoryID,
241 Answered: opts.Answered,
242 OrderBy: orderBy,
243 Direction: direction,
244 }
245 result, err = dc.List(repo, filters, opts.After, opts.Limit)
246 }

Callers 2

TestListRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 14

MatchCategoryFunction · 0.92
NewNoResultsErrorFunction · 0.92
FullNameFunction · 0.92
openInBrowserFunction · 0.85
toFilterStateFunction · 0.85
toOrderByAndDirectionFunction · 0.85
printDiscussionsFunction · 0.85
StartPagerMethod · 0.80
StopPagerMethod · 0.80
BaseRepoMethod · 0.65
ListCategoriesMethod · 0.65
SearchMethod · 0.65

Tested by 1

TestListRunFunction · 0.56