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-Total for 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 RepoName to the group, like mr 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.

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: 33 and expect of 33. Both fail on main with 2 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/... and go vet ./internal/commands/label/list/ pass.

  • golangci-lint run ./internal/commands/label/... (v2.14.0, as pinned in .tool-versions) reports 0 issues, and golangci-lint fmt --diff reports no changes.

  • go run ./scripts/comment-overlap reports 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 main This branch
    glab label list Showing label 30 of 30 on OWNER/REPO. Showing 30 of 33 labels on OWNER/REPO. (Page 1)
    glab label list -p 2 Showing label 3 of 3 on OWNER/REPO. Showing 3 of 33 labels on OWNER/REPO. (Page 2)
    glab label list -P 10 Showing label 10 of 10 on OWNER/REPO. Showing 10 of 33 labels on OWNER/REPO. (Page 1)
    glab label list -g GROUP Showing label 30 of 30 for group GROUP. Showing 30 of 33 labels on GROUP. (Page 1)

    The table body and -F json output are byte-identical to main.

Edited by unstable-code

Merge request reports

Loading
Loading