Commit a26f4166 authored by Patrick Bajao's avatar Patrick Bajao

Merge branch '292714-allow-reviewers-to-be-updated-via-api' into 'master'

Resolve "Allow reviewers to be updated via API"

See merge request gitlab-org/gitlab!51186
parents 25a1f454 e1eaa309
---
title: Allow reviewers to be updated via MergeRequest API
merge_request: 51186
author:
type: added
......@@ -15,6 +15,7 @@ type: reference, api
> - `reference` was [deprecated](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20354) in GitLab 12.10 in favour of `references`.
> - `with_merge_status_recheck` was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31890) in GitLab 13.0.
> - `reviewer_username` and `reviewer_id` were [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49341) in GitLab 13.8.
> - `reviewer_ids` was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51186) in GitLab 13.8.
Every API call to merge requests must be authenticated.
......@@ -1060,6 +1061,8 @@ POST /projects/:id/merge_requests
| `title` | string | yes | Title of MR. |
| `assignee_id` | integer | no | Assignee user ID. |
| `assignee_ids` | integer array | no | The ID of the user(s) to assign the MR to. Set to `0` or provide an empty value to unassign all assignees. |
| `assignee_ids` | integer array | no | The ID of the user(s) to assign the MR to. If set to `0` or left empty, there will be no assignees added. |
| `reviewer_ids` | integer array | no | The ID of the user(s) added as a reviewer to the MR. If set to `0` or left empty, there will be no reviewers added. |
| `description` | string | no | Description of MR. Limited to 1,048,576 characters. |
| `target_project_id` | integer | no | The target project (numeric ID). |
| `labels` | string | no | Labels for MR as a comma-separated list. |
......@@ -1208,6 +1211,7 @@ PUT /projects/:id/merge_requests/:merge_request_iid
| `title` | string | no | Title of MR. |
| `assignee_id` | integer | no | The ID of the user to assign the merge request to. Set to `0` or provide an empty value to unassign all assignees. |
| `assignee_ids` | integer array | no | The ID of the user(s) to assign the MR to. Set to `0` or provide an empty value to unassign all assignees. |
| `reviewer_ids` | integer array | no | The ID of the user(s) set as a reviewer to the MR. Set the value to `0` or provide an empty value to unset all reviewers. |
| `milestone_id` | integer | no | The global ID of a milestone to assign the merge request to. Set to `0` or provide an empty value to unassign a milestone.|
| `labels` | string | no | Comma-separated label names for a merge request. Set to an empty string to unassign all labels. |
| `add_labels` | string | no | Comma-separated label names to add to a merge request. |
......
......@@ -26,6 +26,7 @@ module API
%i[
assignee_id
assignee_ids
reviewer_ids
description
labels
add_labels
......@@ -160,7 +161,8 @@ module API
helpers do
params :optional_params do
optional :assignee_id, type: Integer, desc: 'The ID of a user to assign the merge request'
optional :assignee_ids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'The array of user IDs to assign issue'
optional :assignee_ids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'Comma-separated list of assignee ids'
optional :reviewer_ids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'Comma-separated list of reviewer ids'
optional :description, type: String, desc: 'The description of the merge request'
optional :labels, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
optional :add_labels, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Comma-separated list of label names'
......
......@@ -1736,6 +1736,36 @@ RSpec.describe API::MergeRequests do
end
end
context 'accepts reviewer_ids' do
let(:params) do
{
title: 'Test merge request',
source_branch: 'feature_conflict',
target_branch: 'master',
author_id: user.id,
reviewer_ids: [user2.id]
}
end
it 'creates a new merge request with a reviewer' do
post api("/projects/#{project.id}/merge_requests", user), params: params
expect(response).to have_gitlab_http_status(:created)
expect(json_response['title']).to eq('Test merge request')
expect(json_response['reviewers'].first['name']).to eq(user2.name)
end
it 'creates a new merge request with no reviewer' do
params[:reviewer_ids] = []
post api("/projects/#{project.id}/merge_requests", user), params: params
expect(response).to have_gitlab_http_status(:created)
expect(json_response['title']).to eq('Test merge request')
expect(json_response['reviewers']).to be_empty
end
end
context 'between branches projects' do
context 'different labels' do
let(:params) do
......@@ -2081,6 +2111,34 @@ RSpec.describe API::MergeRequests do
it_behaves_like 'issuable update endpoint' do
let(:entity) { merge_request }
end
context 'accepts reviewer_ids' do
let(:params) do
{
title: 'Updated merge request',
reviewer_ids: [user2.id]
}
end
it 'adds a reviewer to the existing merge request' do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['title']).to eq('Updated merge request')
expect(json_response['reviewers'].first['name']).to eq(user2.name)
end
it 'removes a reviewer from the existing merge request' do
merge_request.reviewers = [user2]
params[:reviewer_ids] = []
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['title']).to eq('Updated merge request')
expect(json_response['reviewers']).to be_empty
end
end
end
describe "POST /projects/:id/merge_requests/:merge_request_iid/context_commits" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment