diff options
Diffstat (limited to 'lib/api/repositories.rb')
-rw-r--r-- | lib/api/repositories.rb | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 3932512d8da..531ef5a63ea 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -19,10 +19,13 @@ module API end def assign_blob_vars! + authorize! :download_code, user_project + @repo = user_project.repository begin @blob = Gitlab::Git::Blob.raw(@repo, params[:sha]) + @blob.load_all_data!(@repo) rescue not_found! 'Blob' end @@ -35,13 +38,13 @@ module API success Entities::RepoTreeObject end params do - optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used' + optional :ref, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used' optional :path, type: String, desc: 'The path of the tree' optional :recursive, type: Boolean, default: false, desc: 'Used to get a recursive tree' use :pagination end get ':id/repository/tree' do - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' + ref = params[:ref] || user_project.try(:default_branch) || 'master' path = params[:path] || nil commit = user_project.commit(ref) @@ -52,44 +55,23 @@ module API present paginate(entries), with: Entities::RepoTreeObject end - desc 'Get a raw file contents' + desc 'Get raw blob contents from the repository' params do requires :sha, type: String, desc: 'The commit, branch name, or tag name' - requires :filepath, type: String, desc: 'The path to the file to display' - end - get ":id/repository/commits/:sha/blob" do - repo = user_project.repository - - commit = repo.commit(params[:sha]) - not_found! "Commit" unless commit - - blob = Gitlab::Git::Blob.find(repo, commit.id, params[:filepath]) - not_found! "File" unless blob - - send_git_blob repo, blob end - - desc 'Get raw blob by sha' - params do - requires :sha, type: String, desc: 'The commit, branch name, or tag name' - end - get ':id/repository/blobs/:sha/:raw' do + get ':id/repository/blobs/:sha/raw' do assign_blob_vars! - status(200) - send_git_blob @repo, @blob end - desc 'Get blob base4 encoded content by sha' + desc 'Get a blob from the repository' params do requires :sha, type: String, desc: 'The commit, branch name, or tag name' end get ':id/repository/blobs/:sha' do assign_blob_vars! - status(200) - { size: @blob.size, encoding: "base64", |