From 7381944565701f2a8db5d58d5bc3c7e52e7f60bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarka=20Kadlecova=CC=81?= Date: Wed, 31 Jan 2018 15:59:59 +0100 Subject: Support search in API --- lib/api/entities.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index e13463ec66b..7838de13c56 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -314,24 +314,20 @@ module API end end - class ProjectSnippet < Grape::Entity + class Snippet < Grape::Entity expose :id, :title, :file_name, :description expose :author, using: Entities::UserBasic expose :updated_at, :created_at - - expose :web_url do |snippet, options| + expose :project_id + expose :web_url do |snippet| Gitlab::UrlBuilder.build(snippet) end end - class PersonalSnippet < Grape::Entity - expose :id, :title, :file_name, :description - expose :author, using: Entities::UserBasic - expose :updated_at, :created_at + class ProjectSnippet < Snippet + end - expose :web_url do |snippet| - Gitlab::UrlBuilder.build(snippet) - end + class PersonalSnippet < Snippet expose :raw_url do |snippet| Gitlab::UrlBuilder.build(snippet) + "/raw" end @@ -1168,5 +1164,14 @@ module API class ApplicationWithSecret < Application expose :secret end + + class Blob < Grape::Entity + expose :basename + expose :data + expose :filename + expose :id + expose :ref + expose :startline + end end end -- cgit v1.2.1 From b7cd99c376c2f953f30a4bf982b69780e3d6985b Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Fri, 22 Dec 2017 16:54:55 +0100 Subject: Allow including custom attributes in API responses --- lib/api/entities.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7838de13c56..dc8e2b26316 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -22,6 +22,7 @@ module API end expose :avatar_path, if: ->(user, options) { options.fetch(:only_path, false) && user.avatar_path } + expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes expose :web_url do |user, options| Gitlab::Routing.url_helpers.user_url(user) @@ -109,6 +110,8 @@ module API expose :star_count, :forks_count expose :last_activity_at + expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + def self.preload_relation(projects_relation, options = {}) projects_relation.preload(:project_feature, :route) .preload(namespace: [:route, :owner], @@ -230,6 +233,8 @@ module API expose :parent_id end + expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :statistics, if: :statistics do with_options format_with: -> (value) { value.to_i } do expose :storage_size -- cgit v1.2.1 From cea2a8f741d623ca2085e8149112de3a20a4779f Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 24 Oct 2017 13:28:06 +0300 Subject: Basic ref fetching for commits --- lib/api/entities.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7838de13c56..e8c9ba6fce5 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -276,7 +276,17 @@ module API expose :last_pipeline, using: 'API::Entities::PipelineBasic' end - class Branch < Grape::Entity + class BasicRef < Grape::Entity + expose :name + end + + class SimpleRef < Grape::Entity + expose :name do |ref, options| + ref + end + end + + class Branch < BasicRef expose :name expose :commit, using: Entities::Commit do |repo_branch, options| @@ -845,8 +855,8 @@ module API expose :description end - class Tag < Grape::Entity - expose :name, :message + class Tag < BasicRef + expose :message expose :commit, using: Entities::Commit do |repo_tag, options| options[:project].repository.commit(repo_tag.dereferenced_target) -- cgit v1.2.1 From 4cefb568d96c4868404caa14534a4329e2dd887f Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 9 Feb 2018 14:30:27 +0100 Subject: Incorporate feedback --- lib/api/entities.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index e8c9ba6fce5..054c04bbd98 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -277,16 +277,12 @@ module API end class BasicRef < Grape::Entity - expose :name - end - - class SimpleRef < Grape::Entity expose :name do |ref, options| ref end end - class Branch < BasicRef + class Branch < Grape::Entity expose :name expose :commit, using: Entities::Commit do |repo_branch, options| @@ -855,8 +851,8 @@ module API expose :description end - class Tag < BasicRef - expose :message + class Tag < Grape::Entity + expose :name, :message expose :commit, using: Entities::Commit do |repo_tag, options| options[:project].repository.commit(repo_tag.dereferenced_target) -- cgit v1.2.1 From 922d156a5e0412a12662df94e03479f7ed015f7b Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 9 Feb 2018 17:46:41 +0100 Subject: Separate branch and tag names --- lib/api/entities.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 054c04bbd98..c7a817877f0 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -277,8 +277,12 @@ module API end class BasicRef < Grape::Entity - expose :name do |ref, options| - ref + expose :branch_name, if: lambda { |ref, options| ref[1] } do |ref, options| + ref[0] + end + + expose :tag_name, if: lambda { |ref, options| !ref[1] } do |ref, options| + ref[0] end end -- cgit v1.2.1 From 848f49801d2c45227c525fb5ecdf8b71e7711ded Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 12 Feb 2018 12:40:55 +0100 Subject: add entity and update spec --- lib/api/entities.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7838de13c56..8fbad2b6959 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -90,6 +90,11 @@ module API expose :created_at end + class ProjectImportStatus < ProjectIdentity + expose :import_status + expose :import_error, if: :import_error + end + class BasicProjectDetails < ProjectIdentity include ::API::ProjectsRelationBuilder -- cgit v1.2.1 From 4a0d56daacc3f1825c5f9644a0ea63842fa9da7d Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 13 Feb 2018 09:47:47 +0100 Subject: fix entity --- lib/api/entities.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 8fbad2b6959..ffdb06b8094 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -92,7 +92,9 @@ module API class ProjectImportStatus < ProjectIdentity expose :import_status - expose :import_error, if: :import_error + + # TODO: Use `expose_nil` once we upgrade the grape-entity gem + expose :import_error, if: lambda { |status, _ops| status.import_error } end class BasicProjectDetails < ProjectIdentity -- cgit v1.2.1 From b0b4ae1875529cd7ca786bd5eccd49be9a40a038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarka=20Kadlecov=C3=A1?= Date: Tue, 13 Feb 2018 13:41:35 +0100 Subject: API - Include project in commits&blobs search results --- lib/api/entities.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7838de13c56..1608af97d38 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -274,6 +274,7 @@ module API expose :stats, using: Entities::CommitStats, if: :stats expose :status expose :last_pipeline, using: 'API::Entities::PipelineBasic' + expose :project_id end class Branch < Grape::Entity @@ -1172,6 +1173,7 @@ module API expose :id expose :ref expose :startline + expose :project_id end end end -- cgit v1.2.1 From a724f7e35f9f8ed9692b0f3f4d6c8a62632cdec4 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 13 Feb 2018 20:22:37 +0100 Subject: Refactor commits/refs API to use hash and add pagination headers --- lib/api/entities.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index c7a817877f0..c8cda85b170 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -277,13 +277,7 @@ module API end class BasicRef < Grape::Entity - expose :branch_name, if: lambda { |ref, options| ref[1] } do |ref, options| - ref[0] - end - - expose :tag_name, if: lambda { |ref, options| !ref[1] } do |ref, options| - ref[0] - end + expose :type, :name end class Branch < Grape::Entity -- cgit v1.2.1