summaryrefslogtreecommitdiff
path: root/lib/api/files.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-09 09:42:29 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-09 09:42:29 +0000
commitca196453f000c81d2f476827d718d010a128cf10 (patch)
tree08430bc1bc4262513eeeee50ed3dd3504979ae74 /lib/api/files.rb
parentea3680ad80e7623e03341a2568e775527bd47fd3 (diff)
parentf64dd1b492952083449dc7f0e226cf7b20e1a1fb (diff)
downloadgitlab-ce-ca196453f000c81d2f476827d718d010a128cf10.tar.gz
Merge branch 'feature/api_create_file' of /home/git/repositories/gitlab/gitlabhq
Diffstat (limited to 'lib/api/files.rb')
-rw-r--r--lib/api/files.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb
new file mode 100644
index 00000000000..5918b6e5ca0
--- /dev/null
+++ b/lib/api/files.rb
@@ -0,0 +1,41 @@
+module API
+ # Projects API
+ class Files < Grape::API
+ before { authenticate! }
+ before { authorize! :push_code, user_project }
+
+ resource :projects do
+ # Create new file in repository
+ #
+ # Parameters:
+ # file_name (required) - The name of new file. Ex. class.rb
+ # file_path (optiona) - 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:
+ # 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]
+ 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
+
+ if result[:status] == :success
+ status(201)
+
+ {
+ file_name: attrs[:file_name],
+ file_path: file_path,
+ branch_name: branch_name
+ }
+ else
+ render_api_error!(result[:error], 400)
+ end
+ end
+ end
+ end
+end
+