Draft: feat(work-items): use the REST API for all work items commands

Description

Moves every glab work-items command onto the experimental work items REST API, through client-go, and adds a get command.

glab calls client-go's WorkItemsService for every command. The REST support itself is in the client-go MR gitlab-org/api/client-go!3064 (closed), which moves WorkItemsService from GraphQL to REST without changing its public API. That means this MR builds against the current client-go release too: with v3.14.0 the commands still use GraphQL, and they switch to REST once go.mod points at a client-go release that includes gitlab-org/api/client-go!3064 (closed).

Command Change
list Calls client.WorkItems.ListWorkItems. The --after flag uses the returned PageInfo.EndCursor. The table is unchanged.
get (new, alias view) Calls client.WorkItems.GetWorkItem and shows type, title, state, author, assignees, labels, milestone, dates, URL, and description. client-go returns only the milestone ID, so get looks up the title and shows the ID when the milestone belongs elsewhere, such as an ancestor group.
create, update, delete Call the matching client.WorkItems methods, as before.

internal/commands/workitems/api converts client-go's WorkItem to glab's JSON output and names the work item, project, or group in not-found errors.

Behavior changes

  • --output json uses the REST representation for every command: snake_case keys (iid, web_url, work_item_type), numeric IIDs, and lowercase states (opened, closed).
    • list previously printed the GraphQL shape: workItemType, webUrl, "iid": "1", "state": "OPEN". The data/pagination wrapper is unchanged, and the text table still shows OPEN/CLOSED.
    • create and update previously printed client-go's WorkItem struct (IID, WebURL, …).
    • get is new and uses the same shape.
  • With the REST-based client-go, the endpoints are behind the work_item_rest_api feature flag (rollout: gitlab#588874). While it is off they return 404, and glab's error says so.

Known limitations

  • The REST list endpoint currently ignores the feature flag: gitlab#631194 (closed).
  • --weight requires GitLab Premium or Ultimate. On other tiers the API accepts it but does not apply it.

Related to gitlab#631130 (closed)

How has this been tested?

Unit tests: go test ./internal/commands/workitems/... and golangci-lint run ./internal/commands/workitems/... pass. Tests use client-go's generated mocks; the create, update, and delete tests are the ones from main, plus not-found cases.

Manually against a local GDK with work_item_rest_api enabled, building glab against the client-go branch through a Go workspace:

  1. list, including cursor pagination to page 2.
  2. create --type task --description … → update (title, assignee, milestone, due date) → update --attach → get (milestone title shown) → delete → get returns the not-found error.
  3. create --confidential shows opened (confidential) in get.
  4. With GLAB_DEBUG_HTTP=true, only /api/v4/namespaces/…/-/work_items requests were made and no POST /api/graphql.
Edited by Phil Wong

Merge request reports

Loading
Loading