Commit d849f58a authored by David Kim's avatar David Kim

Add reviewers to MergeRequest API responses

parent 36513a0e
......@@ -274,7 +274,7 @@ class MergeRequest < ApplicationRecord
scope :with_api_entity_associations, -> {
preload_routables
.preload(:assignees, :author, :unresolved_notes, :labels, :milestone,
:timelogs, :latest_merge_request_diff,
:timelogs, :latest_merge_request_diff, :reviewers,
target_project: :project_feature,
metrics: [:latest_closed_by, :merged_by])
}
......
......@@ -27,6 +27,7 @@ module API
expose(:downvotes) { |merge_request, options| issuable_metadata.downvotes }
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 :labels do |merge_request, options|
if options[:with_labels_details]
......
......@@ -40,4 +40,31 @@ RSpec.describe ::API::Entities::MergeRequestBasic do
expect(batch.count).to be_within(3 * query.count).of(control.count)
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
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