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

Function ResolveFieldByID

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

ResolveFieldByID finds the project field whose node ID matches id, validating it against the fields returned with the project so an unknown ID fails with a candidate-carrying *FieldIDNotFoundError instead of silently rendering an empty column. Node IDs are matched exactly (they are case-sensitive).

(fields []ProjectField, id string)

Source from the content-addressed store, hash-verified

95// candidate-carrying *FieldIDNotFoundError instead of silently rendering an
96// empty column. Node IDs are matched exactly (they are case-sensitive).
97func ResolveFieldByID(fields []ProjectField, id string) (ProjectField, error) {
98 for _, f := range fields {
99 if f.ID() == id {
100 return f, nil
101 }
102 }
103 candidates := make([]string, 0, len(fields))
104 for _, f := range fields {
105 candidates = append(candidates, fmt.Sprintf("%s (%s)", f.Name(), f.ID()))
106 }
107 sort.Strings(candidates)
108 return ProjectField{}, &FieldIDNotFoundError{ID: id, Candidates: candidates}
109}

Callers 2

resolveFieldColumnsFunction · 0.92
TestResolveFieldByIDFunction · 0.85

Calls 2

IDMethod · 0.65
NameMethod · 0.65

Tested by 1

TestResolveFieldByIDFunction · 0.68