BigW Consortium Gitlab

tree_root_entity.rb 715 Bytes
Newer Older
1 2
# TODO: Inherit from TreeEntity, when `Tree` implements `id` and `name` like `Gitlab::Git::Tree`.
class TreeRootEntity < Grape::Entity
Jacob Schatz committed
3 4
  include RequestAwareEntity

5
  expose :path
Jacob Schatz committed
6

7 8 9
  expose :trees, using: TreeEntity
  expose :blobs, using: BlobEntity
  expose :submodules, using: SubmoduleEntity
Jacob Schatz committed
10 11 12 13 14 15 16 17 18 19 20

  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
21 22 23 24

  expose :last_commit_path do |tree|
    logs_file_project_ref_path(request.project, request.ref, tree.path)
  end
25
end