Commit 903d91af authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '290998-add-reviewers-to-api-responses' into 'master'

Add reviewers to MergeRequest API responses

See merge request gitlab-org/gitlab!49192
parents fd596294 d849f58a
...@@ -274,7 +274,7 @@ class MergeRequest < ApplicationRecord ...@@ -274,7 +274,7 @@ class MergeRequest < ApplicationRecord
scope :with_api_entity_associations, -> { scope :with_api_entity_associations, -> {
preload_routables preload_routables
.preload(:assignees, :author, :unresolved_notes, :labels, :milestone, .preload(:assignees, :author, :unresolved_notes, :labels, :milestone,
:timelogs, :latest_merge_request_diff, :timelogs, :latest_merge_request_diff, :reviewers,
target_project: :project_feature, target_project: :project_feature,
metrics: [:latest_closed_by, :merged_by]) metrics: [:latest_closed_by, :merged_by])
} }
......
...@@ -27,6 +27,7 @@ module API ...@@ -27,6 +27,7 @@ module API
expose(:downvotes) { |merge_request, options| issuable_metadata.downvotes } expose(:downvotes) { |merge_request, options| issuable_metadata.downvotes }
expose :author, :assignees, :assignee, using: Entities::UserBasic expose :author, :assignees, :assignee, using: Entities::UserBasic
expose :reviewers, if: -> (merge_request, _) { merge_request.allows_reviewers? }, using: Entities::UserBasic
expose :source_project_id, :target_project_id expose :source_project_id, :target_project_id
expose :labels do |merge_request, options| expose :labels do |merge_request, options|
if options[:with_labels_details] if options[:with_labels_details]
......
...@@ -40,4 +40,31 @@ RSpec.describe ::API::Entities::MergeRequestBasic do ...@@ -40,4 +40,31 @@ RSpec.describe ::API::Entities::MergeRequestBasic do
expect(batch.count).to be_within(3 * query.count).of(control.count) expect(batch.count).to be_within(3 * query.count).of(control.count)
end end
end end
context 'reviewers' do
context "when merge_request_reviewers FF is enabled" do
before do
stub_feature_flags(merge_request_reviewers: true)
merge_request.reviewers = [user]
end
it 'includes assigned reviewers' do
result = Gitlab::Json.parse(present(merge_request).to_json)
expect(result['reviewers'][0]['username']).to eq user.username
end
end
context "when merge_request_reviewers FF is disabled" do
before do
stub_feature_flags(merge_request_reviewers: false)
end
it 'does not include reviewers' do
result = Gitlab::Json.parse(present(merge_request).to_json)
expect(result.keys).not_to include('reviewers')
end
end
end
end end
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