summaryrefslogtreecommitdiff
path: root/lib/api/files.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-11 13:29:35 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-11 13:29:35 +0200
commitb9b9fe70b8fd2deac5dd795e3f220ea90171a75f (patch)
treefb0b0de649268c9a222c297761f224d168e5fa72 /lib/api/files.rb
parent9d029a05f1a6e35228bfb094ad2bd8369b7ee45f (diff)
downloadgitlab-ce-b9b9fe70b8fd2deac5dd795e3f220ea90171a75f.tar.gz
Revert "Fix editing files via API"
This reverts commit 7bde6ae540bab5c93a83bfe26102674adba0eab5.
Diffstat (limited to 'lib/api/files.rb')
-rw-r--r--lib/api/files.rb50
1 files changed, 24 insertions, 26 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb
index c7b30cf2f07..e0ea6d7dd1d 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -3,26 +3,6 @@ module API
class Files < Grape::API
before { authenticate! }
- helpers do
- def commit_params(attrs)
- {
- file_path: attrs[:file_path],
- current_branch: attrs[:branch_name],
- target_branch: attrs[:branch_name],
- commit_message: attrs[:commit_message],
- file_content: attrs[:content],
- file_content_encoding: attrs[:encoding]
- }
- end
-
- def commit_response(attrs)
- {
- file_path: attrs[:file_path],
- branch_name: attrs[:branch_name],
- }
- end
- end
-
resource :projects do
# Get file from repository
# File content is Base64 encoded
@@ -93,11 +73,17 @@ module API
required_attributes! [:file_path, :branch_name, :content, :commit_message]
attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message, :encoding]
- result = ::Files::CreateService.new(user_project, current_user, commit_params(attrs)).execute
+ branch_name = attrs.delete(:branch_name)
+ file_path = attrs.delete(:file_path)
+ result = ::Files::CreateService.new(user_project, current_user, attrs, branch_name, file_path).execute
if result[:status] == :success
status(201)
- commit_response(attrs)
+
+ {
+ file_path: file_path,
+ branch_name: branch_name
+ }
else
render_api_error!(result[:message], 400)
end
@@ -119,11 +105,17 @@ module API
required_attributes! [:file_path, :branch_name, :content, :commit_message]
attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message, :encoding]
- result = ::Files::UpdateService.new(user_project, current_user, commit_params(attrs)).execute
+ branch_name = attrs.delete(:branch_name)
+ file_path = attrs.delete(:file_path)
+ result = ::Files::UpdateService.new(user_project, current_user, attrs, branch_name, file_path).execute
if result[:status] == :success
status(200)
- commit_response(attrs)
+
+ {
+ file_path: file_path,
+ branch_name: branch_name
+ }
else
http_status = result[:http_status] || 400
render_api_error!(result[:message], http_status)
@@ -146,11 +138,17 @@ module API
required_attributes! [:file_path, :branch_name, :commit_message]
attrs = attributes_for_keys [:file_path, :branch_name, :commit_message]
- result = ::Files::DeleteService.new(user_project, current_user, commit_params(attrs)).execute
+ branch_name = attrs.delete(:branch_name)
+ file_path = attrs.delete(:file_path)
+ result = ::Files::DeleteService.new(user_project, current_user, attrs, branch_name, file_path).execute
if result[:status] == :success
status(200)
- commit_response(attrs)
+
+ {
+ file_path: file_path,
+ branch_name: branch_name
+ }
else
render_api_error!(result[:message], 400)
end