diff options
author | Stan Hu <stanhu@gmail.com> | 2017-07-11 00:58:23 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-07-11 16:32:13 +0300 |
commit | e17ac5705dd84ede3ae079051adcb66200457338 (patch) | |
tree | a7b0000d3dab6c48499bb963e6ec5cfdfeb6e049 /lib | |
parent | 01dabbd5c94b494a1833c4e0395032cc81f85dce (diff) |
Add a simple mode to merge request API
The current "basic" merge request API still loads too much data. For integrations
like the Trello Power-up, we just need the basics.
Closes #34920
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 7 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 25 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 945f2821d72..47742a164fc 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -314,6 +314,13 @@ module API expose :id end + class MergeRequestSimple < ProjectEntity + expose :title + expose :web_url do |merge_request, options| + Gitlab::UrlBuilder.build(merge_request) + end + end + class MergeRequestBasic < ProjectEntity expose :target_branch, :source_branch expose :upvotes do |merge_request, options| diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 1a3fdb66f3f..aace6553e2e 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -44,9 +44,14 @@ module API args[:label_name] = args.delete(:labels) merge_requests = MergeRequestsFinder.new(current_user, args).execute - merge_requests = merge_requests.reorder(args[:order_by] => args[:sort]) - paginate(merge_requests) - .preload(:notes, :target_project, :author, :assignee, :milestone, :merge_request_diff, :labels) + .reorder(args[:order_by] => args[:sort]) + merge_requests = paginate(merge_requests) + .preload(:target_project) + + return merge_requests if params[:simple] + + merge_requests + .preload(:notes, :author, :assignee, :milestone, :merge_request_diff, :labels) end params :optional_params_ce do @@ -77,15 +82,25 @@ module API optional :labels, type: String, desc: 'Comma-separated list of label names' optional :created_after, type: DateTime, desc: 'Return merge requests created after the specified time' optional :created_before, type: DateTime, desc: 'Return merge requests created before the specified time' + optional :simple, type: Boolean, default: false, desc: 'Returns the `iid`, URL, title, description, and basic state of merge request' use :pagination end get ":id/merge_requests" do authorize! :read_merge_request, user_project merge_requests = find_merge_requests(project_id: user_project.id) - issuable_metadata = issuable_meta_data(merge_requests, 'MergeRequest') - present merge_requests, with: Entities::MergeRequestBasic, current_user: current_user, project: user_project, issuable_metadata: issuable_metadata + options = { with: Entities::MergeRequestBasic, + current_user: current_user, + project: user_project } + + if params[:simple] + options[:with] = Entities::MergeRequestSimple + else + options[:issuable_metadata] = issuable_meta_data(merge_requests, 'MergeRequest') + end + + present merge_requests, options end desc 'Create a merge request' do |