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

Function ResolveSingleSelectOptionID

pkg/cmd/project/shared/queries/resolve.go:82–115  ·  view source on GitHub ↗

ResolveSingleSelectOptionID resolves optionName to its option ID on a single-select field. It returns a *WrongFieldTypeError if the field is not a single-select field, a *OptionNotFoundError if no option matches, and a *OptionAmbiguousError if more than one option shares the name.

(field ProjectField, optionName string)

Source from the content-addressed store, hash-verified

80// single-select field, a *OptionNotFoundError if no option matches, and a
81// *OptionAmbiguousError if more than one option shares the name.
82func ResolveSingleSelectOptionID(field ProjectField, optionName string) (string, error) {
83 if field.Type() != "ProjectV2SingleSelectField" {
84 return "", &WrongFieldTypeError{
85 FieldName: field.Name(),
86 DataType: field.DataType(),
87 Expected: "SINGLE_SELECT",
88 }
89 }
90
91 var matches []string
92 for _, o := range field.Options() {
93 // Matching is case-insensitive to mirror the Projects v2 platform API,
94 // whose options(names:) argument downcases before matching. Unlike field
95 // names, option names are not guaranteed case-insensitively unique, so
96 // EqualFold may match more than one option; that still fires the
97 // OptionAmbiguousError path below.
98 if strings.EqualFold(o.Name, optionName) {
99 matches = append(matches, o.ID)
100 }
101 }
102
103 switch len(matches) {
104 case 1:
105 return matches[0], nil
106 case 0:
107 names := make([]string, 0, len(field.Options()))
108 for _, o := range field.Options() {
109 names = append(names, o.Name)
110 }
111 return "", &OptionNotFoundError{FieldName: field.Name(), Name: optionName, Candidates: names}
112 default:
113 return "", &OptionAmbiguousError{FieldName: field.Name(), Name: optionName, Candidates: matches}
114 }
115}
116
117// projectItemByURL resolves an issue or pull request URL to the ID of its
118// corresponding item on the project identified by projectID. It is used to let

Callers 2

resolveItemEditNamesFunction · 0.92

Calls 4

DataTypeMethod · 0.80
OptionsMethod · 0.80
NameMethod · 0.65
TypeMethod · 0.45

Tested by 1