diff options
Diffstat (limited to 'lib/api/files.rb')
-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 |