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

Function ResolveFieldByName

pkg/cmd/project/shared/queries/resolve_fields.go:65–91  ·  view source on GitHub ↗

ResolveFieldByName finds the single project field whose name matches name, case-insensitively. Matching is case-insensitive to mirror the Projects v2 platform API, which normalizes field names via a name_slug (name.downcase.gsub(" ","-")) and so guarantees field names are case-insensitively unique;

(fields []ProjectField, name string)

Source from the content-addressed store, hash-verified

63// *FieldAmbiguousError when more than one field shares the name, each carrying
64// candidates so the error is self-correctable.
65func ResolveFieldByName(fields []ProjectField, name string) (ProjectField, error) {
66 var matches []ProjectField
67 for _, f := range fields {
68 if strings.EqualFold(f.Name(), name) {
69 matches = append(matches, f)
70 }
71 }
72
73 switch len(matches) {
74 case 1:
75 return matches[0], nil
76 case 0:
77 names := make([]string, 0, len(fields))
78 for _, f := range fields {
79 names = append(names, f.Name())
80 }
81 sort.Strings(names)
82 return ProjectField{}, &FieldNotFoundError{Name: name, Candidates: names}
83 default:
84 ids := make([]string, 0, len(matches))
85 for _, f := range matches {
86 ids = append(ids, f.ID())
87 }
88 sort.Strings(ids)
89 return ProjectField{}, &FieldAmbiguousError{Name: name, Candidates: ids}
90 }
91}
92
93// ResolveFieldByID finds the project field whose node ID matches id, validating
94// it against the fields returned with the project so an unknown ID fails with a

Callers 3

resolveFieldColumnsFunction · 0.92
resolveItemEditNamesFunction · 0.92
TestResolveFieldByNameFunction · 0.85

Calls 2

NameMethod · 0.65
IDMethod · 0.65

Tested by 1

TestResolveFieldByNameFunction · 0.68