fix(label): show the real total in the list header
Description
glab label list passed len(labels) as both the count and the total in its
header, so the total was always the size of the current page. A project with 33
labels showed Showing label 30 of 30 with the default page size, and
3 of 3 on page 2.
This keeps the *gitlab.Response returned by ListLabels and
ListGroupLabels, and builds the header with utils.NewListTitle, as other
list commands do (modelled on container_registry/repository/list):
- The total comes from
resp.TotalItems. - When the response carries no total (GitLab omits
X-Totalfor very large result sets), the header omits "of N" instead of repeating the page count. - An empty list prints
No labels available on .... - The group case sets
RepoNameto the group, likemr list.
The header format changes accordingly, for example
Showing label 30 of 30 on OWNER/REPO. becomes
Showing 30 of 33 labels on OWNER/REPO. (Page 1), and the group header reads
on GROUP instead of for group GROUP.
The table body and the JSON output are unchanged.
Related Issues
Resolves #8573 (closed)
Related to #1165, which covers list commands that print no total at all.
glab iteration list has the same header bug and will get its own merge
request.
How has this been tested?
-
internal/commands/label/list/label_list_test.go:- Updated the expected headers of the existing cases.
- Project and group cases that mock
TotalItems: 33and expectof 33. Both fail onmainwith2 of 2/1 of 1. - A response without a total, which prints
Showing 2 labels ...with no "of N". - An empty list, which prints
No labels available on OWNER/REPO.
-
go test ./internal/commands/label/...andgo vet ./internal/commands/label/list/pass. -
golangci-lint run ./internal/commands/label/...(v2.14.0, as pinned in.tool-versions) reports 0 issues, andgolangci-lint fmt --diffreports no changes. -
go run ./scripts/comment-overlapreports 0 findings on the changed files. -
Ran a build of this branch against a self-managed GitLab 19.3.3-ee project with 33 labels:
Command mainThis branch glab label listShowing label 30 of 30 on OWNER/REPO.Showing 30 of 33 labels on OWNER/REPO. (Page 1)glab label list -p 2Showing label 3 of 3 on OWNER/REPO.Showing 3 of 33 labels on OWNER/REPO. (Page 2)glab label list -P 10Showing label 10 of 10 on OWNER/REPO.Showing 10 of 33 labels on OWNER/REPO. (Page 1)glab label list -g GROUPShowing label 30 of 30 for group GROUP.Showing 30 of 33 labels on GROUP. (Page 1)The table body and
-F jsonoutput are byte-identical tomain.