diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-11-11 16:58:06 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-11-11 16:58:06 +0400 |
commit | c77d957b365bd023b1dc73b5f5111b4fe262bfbe (patch) | |
tree | 3e954af02803d595ac496656d711542592d7d7b3 /lib | |
parent | 75303241b1ce6a9cb38e40f48ae1bd2ad11808b3 (diff) |
API: Edit file in repository
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/files.rb | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb index 1692d3d3a20..e467b0f8e9a 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -16,9 +16,10 @@ module API # # Example Request: # POST /projects/:id/repository/files + # post ":id/repository/files" do - required_attributes! [:file_name, :branch_name, :content] - attrs = attributes_for_keys [:file_name, :file_path, :branch_name, :content] + required_attributes! [:file_name, :branch_name, :content, :commit_message] + attrs = attributes_for_keys [:file_name, :file_path, :branch_name, :content, :commit_message] branch_name = attrs.delete(:branch_name) file_path = attrs.delete(:file_path) result = ::Files::CreateContext.new(user_project, current_user, attrs, branch_name, file_path).execute @@ -35,6 +36,37 @@ module API render_api_error!(result[:error], 400) end end + + # Update existing file in repository + # + # Parameters: + # file_name (required) - The name of new file. Ex. class.rb + # file_path (optional) - The path to new file. Ex. lib/ + # branch_name (required) - The name of branch + # content (required) - File content + # commit_message (required) - Commit message + # + # Example Request: + # PUT /projects/:id/repository/files + # + put ":id/repository/files" do + required_attributes! [:file_path, :branch_name, :content, :commit_message] + attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message] + branch_name = attrs.delete(:branch_name) + file_path = attrs.delete(:file_path) + result = ::Files::UpdateContext.new(user_project, current_user, attrs, branch_name, file_path).execute + + if result[:status] == :success + status(200) + + { + file_path: file_path, + branch_name: branch_name + } + else + render_api_error!(result[:error], 400) + end + end end end end |