Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-06 19:01:03 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-06 19:01:03 +0400
commitda6f4f06c7b8ad32ae014fd232037ec05e8e8a80 (patch)
treebcac37229f4a8c87278be8ab9c675f343057431a /lib/api/repositories.rb
parent470f9064facd7a5452947ea7d3b650ea885c2195 (diff)
API: implement retrieve of repository tree
Diffstat (limited to 'lib/api/repositories.rb')
-rw-r--r--lib/api/repositories.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index dc75ca7a383..5db17b7e414 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -102,6 +102,31 @@ module API
present commits, with: Entities::RepoCommit
end
+ # Get a project repository tree
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # ref_name (optional) - The name of a repository branch or tag, if not given the default branch is used
+ # Example Request:
+ # GET /projects/:id/repository/tree
+ get ":id/repository/tree" do
+ authorize! :download_code, user_project
+
+ ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
+ path = params[:path] || nil
+
+ commit = user_project.repository.commit(ref)
+ tree = Tree.new(user_project.repository, commit.id, ref, path)
+
+ trees = []
+
+ %w(trees blobs submodules).each do |type|
+ trees += tree.send(type).map { |t| { name: t.name, type: type.singularize, mode: t.mode, id: t.id } }
+ end
+
+ trees
+ end
+
# Get a raw file contents
#
# Parameters: