summaryrefslogtreecommitdiff
path: root/lib/api/files.rb
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-03-08 12:45:42 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-03-08 12:45:42 +0000
commitbb11a062eb19f08dd692da7e54ca9ae13fb23f36 (patch)
treea3c313258a95270d429c5c8a89b6c760e682aa66 /lib/api/files.rb
parent4cbc39bfab32f7c9ac038ba9dcecf14efebb2b9d (diff)
parent685e261f0a9f2495b29e552489e174987101f1f9 (diff)
downloadgitlab-ce-bb11a062eb19f08dd692da7e54ca9ae13fb23f36.tar.gz
Merge branch 'master' into 20450-fix-ujs-actions
* master: (184 commits) fixed user_access_request_spec Fixed changelog and a haml condition project.html.haml Fixed some typos inside the _project.html.haml partial Added MR number to changelog Removed the settings gear button inside the Project to a tab Add changelog for filtered-search-visual-tokens Fix edit last visual token Fix filtered search visual token editing dropdown Code improvements Add filtered search visual tokens Fix transient failure in TodoService spec Returns correct header data for commits endpoint Fix pagination headers for repository commits api endpoint Manually set total_count when paginating commits Fix go-get support for projects in nested groups Remove unecessary endpoint from repository, add compatibility endpoints for v3 and several improvements Add configuration instructions for Container Registry Notifications.[ci skip] Update API endpoints for raw files Clear AR connections before starting Sidekiq API V4 is no longer in Beta ...
Diffstat (limited to 'lib/api/files.rb')
-rw-r--r--lib/api/files.rb62
1 files changed, 38 insertions, 24 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb
index 9c4e43d77cc..bb8f5c3076d 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -14,6 +14,19 @@ module API
}
end
+ def assign_file_vars!
+ authorize! :download_code, user_project
+
+ @commit = user_project.commit(params[:ref])
+ not_found!('Commit') unless @commit
+
+ @repo = user_project.repository
+ @blob = @repo.blob_at(@commit.sha, params[:file_path])
+
+ not_found!('File') unless @blob
+ @blob.load_all_data!(@repo)
+ end
+
def commit_response(attrs)
{
file_path: attrs[:file_path],
@@ -22,7 +35,7 @@ module API
end
params :simple_file_params do
- requires :file_path, type: String, desc: 'The path to new file. Ex. lib/class.rb'
+ requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires :branch, type: String, desc: 'The name of branch'
requires :commit_message, type: String, desc: 'Commit Message'
optional :author_email, type: String, desc: 'The email of the author'
@@ -40,34 +53,35 @@ module API
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
- desc 'Get a file from repository'
+ desc 'Get raw file contents from the repository'
params do
- requires :file_path, type: String, desc: 'The path to the file. Ex. lib/class.rb'
- requires :ref, type: String, desc: 'The name of branch, tag, or commit'
+ requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
+ requires :ref, type: String, desc: 'The name of branch, tag commit'
end
- get ":id/repository/files" do
- authorize! :download_code, user_project
-
- commit = user_project.commit(params[:ref])
- not_found!('Commit') unless commit
+ get ":id/repository/files/:file_path/raw" do
+ assign_file_vars!
- repo = user_project.repository
- blob = repo.blob_at(commit.sha, params[:file_path])
- not_found!('File') unless blob
+ send_git_blob @repo, @blob
+ end
- blob.load_all_data!(repo)
- status(200)
+ desc 'Get a file from the repository'
+ params do
+ requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
+ requires :ref, type: String, desc: 'The name of branch, tag or commit'
+ end
+ get ":id/repository/files/:file_path", requirements: { file_path: /.+/ } do
+ assign_file_vars!
{
- file_name: blob.name,
- file_path: blob.path,
- size: blob.size,
+ file_name: @blob.name,
+ file_path: @blob.path,
+ size: @blob.size,
encoding: "base64",
- content: Base64.strict_encode64(blob.data),
+ content: Base64.strict_encode64(@blob.data),
ref: params[:ref],
- blob_id: blob.id,
- commit_id: commit.id,
- last_commit_id: repo.last_commit_id_for_path(commit.sha, params[:file_path])
+ blob_id: @blob.id,
+ commit_id: @commit.id,
+ last_commit_id: @repo.last_commit_id_for_path(@commit.sha, params[:file_path])
}
end
@@ -75,7 +89,7 @@ module API
params do
use :extended_file_params
end
- post ":id/repository/files" do
+ post ":id/repository/files/:file_path", requirements: { file_path: /.+/ } do
authorize! :push_code, user_project
file_params = declared_params(include_missing: false)
@@ -93,7 +107,7 @@ module API
params do
use :extended_file_params
end
- put ":id/repository/files" do
+ put ":id/repository/files/:file_path", requirements: { file_path: /.+/ } do
authorize! :push_code, user_project
file_params = declared_params(include_missing: false)
@@ -112,7 +126,7 @@ module API
params do
use :simple_file_params
end
- delete ":id/repository/files" do
+ delete ":id/repository/files/:file_path", requirements: { file_path: /.+/ } do
authorize! :push_code, user_project
file_params = declared_params(include_missing: false)