From 618dbf33f0d4d38f72d1b3edd162a5ccadff9e3c Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Tue, 5 May 2026 12:46:33 +0100 Subject: [PATCH] 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> --- pkg/cmd/discussion/client/client_impl.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/discussion/client/client_impl.go b/pkg/cmd/discussion/client/client_impl.go index 6d71ab9ef..78108a233 100644 --- a/pkg/cmd/discussion/client/client_impl.go +++ b/pkg/cmd/discussion/client/client_impl.go @@ -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 }