feat(workitems): add experimental WorkItemsRESTService with GetWorkItem
What does this MR do?
Adds WorkItemsRESTService, a separate service for the work items REST API, starting with one method:
wi, _, err := client.WorkItemsREST.GetWorkItem("my-group/my-project", 41, &gitlab.GetWorkItemRESTOptions{
Fields: []gitlab.WorkItemFieldValue{gitlab.WorkItemFieldState, gitlab.WorkItemFieldAuthor},
Features: []gitlab.WorkItemFeatureValue{gitlab.WorkItemFeatureDescription, gitlab.WorkItemFeatureLabels},
})GetWorkItem calls GET /namespaces/:id/-/work_items/:work_item_iid, so it works for both project and group work items. It accepts the API's fields and features query parameters.
The GraphQL-based WorkItemsService is unchanged. Callers choose which API to use.
Why
This follows the second option in !3064 (comment 3964397033): a new service rather than switching WorkItemsService to REST, so existing users of the GraphQL methods aren't affected and can move to REST when they want. Naming follows the client-go convention: the struct is WorkItemsRESTService, the interface WorkItemsRESTServiceInterface, and the client field WorkItemsREST.
The first consumer is glab's hidden work-items-experimental get command: gitlab-org/cli!4010 (for gitlab-org/cli#8585)
Notes for reviewers
- Experimental: the REST API is behind the
work_item_rest_apifeature flag (off by default) and returns 404 while it's off. The service carries the same experimental note asWorkItemsService. - API docs: the REST API docs page (
doc/api/work_items.md, to be published at https://docs.gitlab.com/api/work_items/) is being written and isn't published yet. The godoc links point to its planned location. - Plain values unless the zero value is valid: the API returns only
id,iid,global_idandtitleunless other fields are requested. Fields whose zero value can't be real data (State,WebURL, …) are plain values. Fields wherefalseor0is a valid answer (Confidential,UserDiscussionsCount, …) are pointers, sonilmeans not requested. Fields the API can leave out are taggedomitzero, so encoded JSON contains only what the API returned. - Features: only the features glab needs first are typed (
assignees,description,hierarchy,labels,milestone,start_and_due_date). The others follow in later MRs. - Test fixture is a real response captured from a local GDK, with host and paths replaced.
How to test
go test -race -run TestWorkItemsREST .