From 5ec28dc387fb4adc3c5b65ac47819a8663186954 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 8 Apr 2019 14:17:22 +0300 Subject: Changes to issues api When issues_controller endpoint was used for search, the parameters passed to the controller were slightly different then the ones passed to API. Because the searchbar UI is reused in different places and builds the parameters passed to request in same way we need to account for old parameter names. Add issues_statistics api endpoints Adds issue_statistics api endpoints for issue lists and returns counts of issues for all, closed and opened states. Expose more label attributes based on a param When requesting issues list through API expose more attributes for labels, like color, description if with_labels_data param is being passed, avoiding this way to change response schema for users that already use API. https://gitlab.com/gitlab-org/gitlab-ce/issues/57402 --- lib/api/entities.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 296688ba25b..a57c7e9f851 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -542,9 +542,13 @@ module API class IssueBasic < ProjectEntity expose :closed_at expose :closed_by, using: Entities::UserBasic - expose :labels do |issue| + expose :labels do |issue, options| # Avoids an N+1 query since labels are preloaded - issue.labels.map(&:title).sort + if options[:with_labels_data] + ::API::Entities::LabelBasic.represent(issue.labels.sort_by(&:title)) + else + issue.labels.map(&:title).sort + end end expose :milestone, using: Entities::Milestone expose :assignees, :author, using: Entities::UserBasic @@ -560,6 +564,8 @@ module API expose :due_date expose :confidential expose :discussion_locked + expose(:has_tasks) {|issue, _| !issue.task_list_items.empty? } + expose :task_status, if: -> (issue, _) { !issue.task_list_items.empty? } expose :web_url do |issue| Gitlab::UrlBuilder.build(issue) -- cgit v1.2.1 From a4fbf39eca4518598e893f6f1b81b8b69927c6f9 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 19 Apr 2019 10:55:36 +0300 Subject: Move issue details to from IssueBasic to Issue entity Cleanup IssueBasic entity to keep it basic and move extra attributes to Issue entity which contains more details --- lib/api/entities.rb | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index a57c7e9f851..1f10dc6c0fc 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -542,13 +542,9 @@ module API class IssueBasic < ProjectEntity expose :closed_at expose :closed_by, using: Entities::UserBasic - expose :labels do |issue, options| + expose :labels do |issue| # Avoids an N+1 query since labels are preloaded - if options[:with_labels_data] - ::API::Entities::LabelBasic.represent(issue.labels.sort_by(&:title)) - else - issue.labels.map(&:title).sort - end + issue.labels.map(&:title).sort end expose :milestone, using: Entities::Milestone expose :assignees, :author, using: Entities::UserBasic @@ -564,8 +560,6 @@ module API expose :due_date expose :confidential expose :discussion_locked - expose(:has_tasks) {|issue, _| !issue.task_list_items.empty? } - expose :task_status, if: -> (issue, _) { !issue.task_list_items.empty? } expose :web_url do |issue| Gitlab::UrlBuilder.build(issue) @@ -579,6 +573,23 @@ module API class Issue < IssueBasic include ::API::Helpers::RelatedResourcesHelpers + expose :labels do |issue, options| + # Avoids an N+1 query since labels are preloaded + if options[:with_labels_data] + ::API::Entities::LabelBasic.represent(issue.labels.sort_by(&:title)) + else + issue.labels.map(&:title).sort + end + end + + expose(:has_tasks) do |issue, _| + !issue.task_list_items.empty? + end + + expose :task_status, if: -> (issue, _) do + !issue.task_list_items.empty? + end + expose :_links do expose :self do |issue| expose_url(api_v4_project_issue_path(id: issue.project_id, issue_iid: issue.iid)) -- cgit v1.2.1 From 9ff6edf690423a284f4d0ad924ff2a9a4285eb50 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 17 May 2019 12:46:33 +0300 Subject: Review updates and cleanup * Cleaned issues and issues_statistics docs * Renamed param with_labels_data to with_labels_details * Added spec for N+1 check when retrieving labels from issue * Refactoed CheckAssigneesCount validation class --- lib/api/entities.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 1f10dc6c0fc..625fada4f08 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -542,10 +542,15 @@ module API class IssueBasic < ProjectEntity expose :closed_at expose :closed_by, using: Entities::UserBasic - expose :labels do |issue| - # Avoids an N+1 query since labels are preloaded - issue.labels.map(&:title).sort + + expose :labels do |issue, options| + if options[:with_labels_details] + ::API::Entities::LabelBasic.represent(issue.labels.sort_by(&:title)) + else + issue.labels.map(&:title).sort + end end + expose :milestone, using: Entities::Milestone expose :assignees, :author, using: Entities::UserBasic @@ -573,15 +578,6 @@ module API class Issue < IssueBasic include ::API::Helpers::RelatedResourcesHelpers - expose :labels do |issue, options| - # Avoids an N+1 query since labels are preloaded - if options[:with_labels_data] - ::API::Entities::LabelBasic.represent(issue.labels.sort_by(&:title)) - else - issue.labels.map(&:title).sort - end - end - expose(:has_tasks) do |issue, _| !issue.task_list_items.empty? end -- cgit v1.2.1