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

Function runList

pkg/cmd/project/item-list/item_list.go:133–189  ·  view source on GitHub ↗
(config listConfig)

Source from the content-addressed store, hash-verified

131}
132
133func runList(config listConfig) error {
134 if config.opts.query != "" {
135 features, err := config.detector.ProjectFeatures()
136 if err != nil {
137 return err
138 }
139 if !features.ProjectItemQuery {
140 return fmt.Errorf("the `--query` flag is not supported on this GitHub host")
141 }
142 }
143
144 canPrompt := config.io.CanPrompt()
145 owner, err := config.client.NewOwner(canPrompt, config.opts.owner)
146 if err != nil {
147 return err
148 }
149
150 // no need to fetch the project if we already have the number
151 if config.opts.number == 0 {
152 project, err := config.client.NewProject(canPrompt, owner, config.opts.number, false)
153 if err != nil {
154 return err
155 }
156 config.opts.number = project.Number
157 }
158
159 project, err := config.client.ProjectItems(owner, config.opts.number, config.opts.limit, config.opts.query)
160 if err != nil {
161 return err
162 }
163
164 if config.opts.exporter != nil {
165 return config.opts.exporter.Write(config.io, project.DetailedItems())
166 }
167
168 // Resolve any requested extra field columns to (header, fieldID) pairs. Name
169 // columns are resolved against the fields already returned with the items, so
170 // there is no separate field-ID preflight lookup. When extra columns are
171 // requested for a project whose field list spans more than one page, fetch the
172 // complete field list first so resolution does not miss fields beyond the
173 // first page.
174 fields := project.Fields.Nodes
175 if (len(config.opts.fields) > 0 || len(config.opts.fieldIDs) > 0) && project.Fields.PageInfo.HasNextPage {
176 withFields, err := config.client.ProjectFields(owner, config.opts.number, project.Fields.TotalCount)
177 if err != nil {
178 return err
179 }
180 fields = withFields.Fields.Nodes
181 }
182
183 extraFields, err := resolveFieldColumns(config.opts, fields)
184 if err != nil {
185 return err
186 }
187
188 return printResults(config, project.Items.Nodes, owner.Login, extraFields)
189}
190

Callers 12

TestRunList_User_ttyFunction · 0.70
TestRunList_UserFunction · 0.70
TestRunList_OrgFunction · 0.70
TestRunList_MeFunction · 0.70
TestRunList_JSONFunction · 0.70
TestRunList_WithQueryFunction · 0.70
TestRunList_FieldColumnFunction · 0.70
NewCmdListFunction · 0.70

Calls 11

DetailedItemsMethod · 0.95
resolveFieldColumnsFunction · 0.85
CanPromptMethod · 0.80
NewOwnerMethod · 0.80
NewProjectMethod · 0.80
ProjectItemsMethod · 0.80
ProjectFieldsMethod · 0.80
printResultsFunction · 0.70
ProjectFeaturesMethod · 0.65
ErrorfMethod · 0.65
WriteMethod · 0.65

Tested by 11

TestRunList_User_ttyFunction · 0.56
TestRunList_UserFunction · 0.56
TestRunList_OrgFunction · 0.56
TestRunList_MeFunction · 0.56
TestRunList_JSONFunction · 0.56
TestRunList_WithQueryFunction · 0.56
TestRunList_FieldColumnFunction · 0.56