Add PUT endpoint to update a note in a work item discussion
What does this MR do and why?
Adds PUT /-/work_items/:work_item_iid/discussions/:discussion_id/notes/:note_id to the work item REST API. It is available in three flavours:
/namespaces/:id/-/work_items/.../projects/:id/-/work_items/.../groups/:id/-/work_items/...
The endpoint updates a single comment (note) inside a discussion thread on a work item. It takes one of these params:
body: edits the note text.resolved: boolean, resolves or unresolves that one note.
Exactly one of the two must be given (exactly_one_of :body, :resolved). Otherwise the API returns 400.
It mirrors the legacy PUT /projects/:id/issues/:iid/discussions/:discussion_id/notes/:note_id endpoint. Issues and work items share the same record, so the behavior matches.
References
- Issue: #604036 (closed)
- Depends on (stacked on) the MR that adds the GET single-note endpoint: !258518 (merged)
- Legacy endpoint docs: https://docs.gitlab.com/api/discussions/#modify-an-existing-issue-thread-note
Screenshots or screen recordings
No UI changes.
How to set up and validate locally
-
Enable the flag in a Rails console:
Feature.enable(:work_item_rest_api) -
Create a project with an issue work item. Start a discussion thread on it, for example with the existing endpoint
POST /api/v4/projects/:id/-/work_items/:work_item_iid/discussionswithbody=hello. Note theidof the discussion and theidof its note from the response. -
Edit the body. Expect 200 with the updated
body.curl --request PUT \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "http://gdk.test:3000/api/v4/projects/<project_id>/-/work_items/<iid>/discussions/<discussion_id>/notes/<note_id>" \ --data "body=updated text" -
Resolve the note. Use the same URL with the data below. Expect 200 with
"resolved": true, andresolved_byandresolved_atset. Then sendresolved=falseto unresolve.curl --request PUT \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "http://gdk.test:3000/api/v4/projects/<project_id>/-/work_items/<iid>/discussions/<discussion_id>/notes/<note_id>" \ --data "resolved=true" -
Send both
bodyandresolved, or neither. Expect 400. -
Repeat with the
/groups/<group_id>/-/work_items/...flavour on an epic work item. Repeat with/namespaces/<full_path_url_encoded>/-/work_items/.... -
Run the specs:
bundle exec rspec spec/requests/api/work_items/discussion_notes_spec.rb ee/spec/requests/api/work_items/discussion_notes_spec.rb
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
This is part 1 of 3 in a stack made with GitButler: