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

Function resolveItemEditNames

pkg/cmd/project/item-edit/item_edit.go:263–326  ·  view source on GitHub ↗

resolveItemEditNames turns the name-based addressing flags into the node IDs used by the field-value mutations: it resolves the project from owner + number, the item from --url, the field from --field, and (for single-select fields) --value from an option name to an option ID. Resolution happens bef

(config editItemConfig)

Source from the content-addressed store, hash-verified

261// happens before the mutation so a bad name fails loudly instead of writing a
262// malformed value.
263func resolveItemEditNames(config editItemConfig) (editItemConfig, error) {
264 canPrompt := config.io.CanPrompt()
265 owner, err := config.client.NewOwner(canPrompt, config.opts.owner)
266 if err != nil {
267 return config, err
268 }
269
270 project, err := config.client.ProjectFields(owner, config.opts.number32, queries.LimitMax)
271 if err != nil {
272 return config, err
273 }
274 config.opts.projectID = project.ID
275
276 // Resolve the field first so a bad field name fails before the item lookup.
277 var field queries.ProjectField
278 if config.opts.field != "" {
279 field, err = queries.ResolveFieldByName(project.Fields.Nodes, config.opts.field)
280 if err != nil {
281 return config, err
282 }
283 config.opts.fieldID = field.ID()
284 }
285
286 if config.opts.url == "" {
287 return config, cmdutil.FlagErrorf("`--url` is required to resolve the item by issue or pull request URL")
288 }
289 itemID, err := config.client.ProjectItemIDByURL(config.opts.url, project.ID, config.opts.number32)
290 if err != nil {
291 return config, err
292 }
293 config.opts.itemID = itemID
294
295 if config.opts.field == "" || !config.opts.valueChanged {
296 return config, nil
297 }
298
299 // Dispatch --value by the resolved field's data type. New enum-like field
300 // types (e.g. MultiSelect) can be added here without reworking callers.
301 switch field.DataType() {
302 case "SINGLE_SELECT":
303 optionID, err := queries.ResolveSingleSelectOptionID(field, config.opts.value)
304 if err != nil {
305 return config, err
306 }
307 config.opts.singleSelectOptionID = optionID
308 case "TEXT":
309 config.opts.text = config.opts.value
310 case "NUMBER":
311 n, err := strconv.ParseFloat(config.opts.value, 64)
312 if err != nil {
313 return config, cmdutil.FlagErrorf("invalid number value %q for field %q", config.opts.value, field.Name())
314 }
315 config.opts.number = n
316 config.opts.numberChanged = true
317 case "DATE":
318 config.opts.date = config.opts.value
319 case "ITERATION":
320 return config, cmdutil.FlagErrorf("setting an iteration field by name is not supported; use `--iteration-id`")

Callers 1

runEditItemFunction · 0.85

Calls 10

IDMethod · 0.95
DataTypeMethod · 0.95
NameMethod · 0.95
ResolveFieldByNameFunction · 0.92
FlagErrorfFunction · 0.92
CanPromptMethod · 0.80
NewOwnerMethod · 0.80
ProjectFieldsMethod · 0.80
ProjectItemIDByURLMethod · 0.80

Tested by

no test coverage detected