diff options
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/analytics_build_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/analytics_issue_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/blob_entity.rb | 17 | ||||
-rw-r--r-- | app/serializers/job_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/merge_request_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/submodule_entity.rb | 23 | ||||
-rw-r--r-- | app/serializers/tree_entity.rb | 17 | ||||
-rw-r--r-- | app/serializers/tree_root_entity.rb | 8 | ||||
-rw-r--r-- | app/serializers/tree_serializer.rb | 3 |
9 files changed, 72 insertions, 4 deletions
diff --git a/app/serializers/analytics_build_entity.rb b/app/serializers/analytics_build_entity.rb index ad7ad020b03..bdc22d71202 100644 --- a/app/serializers/analytics_build_entity.rb +++ b/app/serializers/analytics_build_entity.rb @@ -35,6 +35,6 @@ class AnalyticsBuildEntity < Grape::Entity private def url_to(route, build, id = nil) - public_send("#{route}_url", build.project.namespace, build.project, id || build) + public_send("#{route}_url", build.project.namespace, build.project, id || build) # rubocop:disable GitlabSecurity/PublicSend end end diff --git a/app/serializers/analytics_issue_entity.rb b/app/serializers/analytics_issue_entity.rb index 44c50f18613..b7d95ea020f 100644 --- a/app/serializers/analytics_issue_entity.rb +++ b/app/serializers/analytics_issue_entity.rb @@ -24,6 +24,6 @@ class AnalyticsIssueEntity < Grape::Entity private def url_to(route, id) - public_send("#{route}_url", request.project.namespace, request.project, id) + public_send("#{route}_url", request.project.namespace, request.project, id) # rubocop:disable GitlabSecurity/PublicSend end end diff --git a/app/serializers/blob_entity.rb b/app/serializers/blob_entity.rb new file mode 100644 index 00000000000..56f173e5a27 --- /dev/null +++ b/app/serializers/blob_entity.rb @@ -0,0 +1,17 @@ +class BlobEntity < Grape::Entity + include RequestAwareEntity + + expose :id, :path, :name, :mode + + expose :last_commit do |blob| + request.project.repository.last_commit_for_path(blob.commit_id, blob.path) + end + + expose :icon do |blob| + IconsHelper.file_type_icon_class('file', blob.mode, blob.name) + end + + expose :url do |blob| + project_blob_path(request.project, File.join(request.ref, blob.path)) + end +end diff --git a/app/serializers/job_entity.rb b/app/serializers/job_entity.rb index d6de43bcbcb..72e56a2c77f 100644 --- a/app/serializers/job_entity.rb +++ b/app/serializers/job_entity.rb @@ -46,6 +46,6 @@ class JobEntity < Grape::Entity end def path_to(route, build) - send("#{route}_path", build.project.namespace, build.project, build) + send("#{route}_path", build.project.namespace, build.project, build) # rubocop:disable GitlabSecurity/PublicSend end end diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index 7f17f2bf604..07650ce6f20 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -2,7 +2,6 @@ class MergeRequestEntity < IssuableEntity include RequestAwareEntity expose :in_progress_merge_commit_sha - expose :locked_at expose :merge_commit_sha expose :merge_error expose :merge_params @@ -32,6 +31,7 @@ class MergeRequestEntity < IssuableEntity expose :head_pipeline, with: PipelineDetailsEntity, as: :pipeline # Booleans + expose :merge_ongoing?, as: :merge_ongoing expose :work_in_progress?, as: :work_in_progress expose :source_branch_exists?, as: :source_branch_exists expose :mergeable_discussions_state?, as: :mergeable_discussions_state diff --git a/app/serializers/submodule_entity.rb b/app/serializers/submodule_entity.rb new file mode 100644 index 00000000000..9a7eb5e7880 --- /dev/null +++ b/app/serializers/submodule_entity.rb @@ -0,0 +1,23 @@ +class SubmoduleEntity < Grape::Entity + include RequestAwareEntity + + expose :id, :path, :name, :mode + + expose :icon do |blob| + 'archive' + end + + expose :project_url do |blob| + submodule_links(blob, request).first + end + + expose :tree_url do |blob| + submodule_links(blob, request).last + end + + private + + def submodule_links(blob, request) + @submodule_links ||= SubmoduleHelper.submodule_links(blob, request.ref, request.repository) + end +end diff --git a/app/serializers/tree_entity.rb b/app/serializers/tree_entity.rb new file mode 100644 index 00000000000..555e5cf83bd --- /dev/null +++ b/app/serializers/tree_entity.rb @@ -0,0 +1,17 @@ +class TreeEntity < Grape::Entity + include RequestAwareEntity + + expose :id, :path, :name, :mode + + expose :last_commit do |tree| + request.project.repository.last_commit_for_path(tree.commit_id, tree.path) + end + + expose :icon do |tree| + IconsHelper.file_type_icon_class('folder', tree.mode, tree.name) + end + + expose :url do |tree| + project_tree_path(request.project, File.join(request.ref, tree.path)) + end +end diff --git a/app/serializers/tree_root_entity.rb b/app/serializers/tree_root_entity.rb new file mode 100644 index 00000000000..23b65aa4a4c --- /dev/null +++ b/app/serializers/tree_root_entity.rb @@ -0,0 +1,8 @@ +# TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`. +class TreeRootEntity < Grape::Entity + expose :path + + expose :trees, using: TreeEntity + expose :blobs, using: BlobEntity + expose :submodules, using: SubmoduleEntity +end diff --git a/app/serializers/tree_serializer.rb b/app/serializers/tree_serializer.rb new file mode 100644 index 00000000000..713ade23bc9 --- /dev/null +++ b/app/serializers/tree_serializer.rb @@ -0,0 +1,3 @@ +class TreeSerializer < BaseSerializer + entity TreeRootEntity +end |