diff options
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/tree_root_entity.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/serializers/tree_root_entity.rb b/app/serializers/tree_root_entity.rb index 7eb15ea63b7..69702ae1493 100644 --- a/app/serializers/tree_root_entity.rb +++ b/app/serializers/tree_root_entity.rb @@ -1,8 +1,21 @@ # TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`. class TreeRootEntity < Grape::Entity + include RequestAwareEntity + expose :path expose :trees, using: TreeEntity expose :blobs, using: BlobEntity expose :submodules, using: SubmoduleEntity + + expose :parent_tree_url do |tree| + path = tree.path.sub(%r{\A/}, '') + next unless path.present? + + path_segments = path.split('/') + path_segments.pop + parent_tree_path = path_segments.join('/') + + project_tree_path(request.project, File.join(request.ref, parent_tree_path)) + end end |