fix(discussion/client): improve label resolution error handling
- Break early from pagination when all wanted labels are found - Collect all missing labels and report them in a single error message - Guard missing-label check with len(found) != len(wanted) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
fd06ad7556
commit
618dbf33f0
1 changed files with 14 additions and 5 deletions
|
|
@ -849,19 +849,28 @@ func (c *discussionClient) resolveLabels(repo ghrepo.Interface, labelNames []str
|
|||
found[strings.ToLower(n.Name)] = DiscussionLabel{ID: n.ID, Name: n.Name, Color: n.Color}
|
||||
}
|
||||
}
|
||||
if len(found) == len(wanted) {
|
||||
break
|
||||
}
|
||||
if !query.Repository.Labels.PageInfo.HasNextPage {
|
||||
break
|
||||
}
|
||||
variables["endCursor"] = githubv4.String(query.Repository.Labels.PageInfo.EndCursor)
|
||||
}
|
||||
|
||||
if len(found) != len(wanted) {
|
||||
var missing []string
|
||||
for _, name := range labelNames {
|
||||
if _, ok := found[strings.ToLower(name)]; !ok {
|
||||
missing = append(missing, name)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("labels not found: %s", strings.Join(missing, ", "))
|
||||
}
|
||||
|
||||
result := make([]DiscussionLabel, 0, len(labelNames))
|
||||
for _, name := range labelNames {
|
||||
label, ok := found[strings.ToLower(name)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("label not found: %q", name)
|
||||
}
|
||||
result = append(result, label)
|
||||
result = append(result, found[strings.ToLower(name)])
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue