MCPcopy
hub / github.com/cli/cli / ResolveLabels

Function ResolveLabels

pkg/cmd/discussion/shared/labels.go:13–37  ·  view source on GitHub ↗

ResolveLabels matches user-provided label names (case-insensitive) against a set of known labels and returns the corresponding IDs. If any names cannot be matched, all unrecognized names are reported in the returned error.

(allLabels []client.DiscussionLabel, names []string)

Source from the content-addressed store, hash-verified

11// set of known labels and returns the corresponding IDs. If any names cannot be
12// matched, all unrecognized names are reported in the returned error.
13func ResolveLabels(allLabels []client.DiscussionLabel, names []string) ([]string, error) {
14 byName := make(map[string]string, len(allLabels))
15 for _, l := range allLabels {
16 byName[strings.ToLower(l.Name)] = l.ID
17 }
18
19 var ids []string
20 var missing []string
21
22 for _, name := range names {
23 trimmed := strings.TrimSpace(name)
24 id, ok := byName[strings.ToLower(trimmed)]
25 if !ok {
26 missing = append(missing, trimmed)
27 } else {
28 ids = append(ids, id)
29 }
30 }
31
32 if len(missing) > 0 {
33 return nil, fmt.Errorf("labels not found: %s", strings.Join(missing, ", "))
34 }
35
36 return ids, nil
37}

Callers 3

createRunFunction · 0.92
editRunFunction · 0.92
TestResolveLabelsFunction · 0.85

Calls 2

JoinMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestResolveLabelsFunction · 0.68