diff options
author | dosire <sytses@gmail.com> | 2014-02-21 15:36:53 +0100 |
---|---|---|
committer | dosire <sytses@gmail.com> | 2014-02-21 15:36:53 +0100 |
commit | 403298317f0035be27a812dae9c5090a51c11faa (patch) | |
tree | 9ea82a9ffb93d6f8d10cf37b8f1c04da5b4c6726 /lib/api/files.rb | |
parent | 77dc5de9233db897f7eaf50f4fd0f230b17b555d (diff) | |
parent | bbd92f554d22911afca9fca67077c73e8826bf23 (diff) | |
download | gitlab-ce-403298317f0035be27a812dae9c5090a51c11faa.tar.gz |
Merge branch 'master' into styleguide
Conflicts:
CONTRIBUTING.md
Diffstat (limited to 'lib/api/files.rb')
-rw-r--r-- | lib/api/files.rb | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb index 213604915a6..e0c46f92b84 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -5,10 +5,61 @@ module API before { authorize! :push_code, user_project } resource :projects do + # Get file from repository + # File content is Base64 encoded + # + # Parameters: + # file_path (required) - The path to the file. Ex. lib/class.rb + # ref (required) - The name of branch, tag or commit + # + # Example Request: + # GET /projects/:id/repository/files + # + # Example response: + # { + # "file_name": "key.rb", + # "file_path": "app/models/key.rb", + # "size": 1476, + # "encoding": "base64", + # "content": "IyA9PSBTY2hlbWEgSW5mb3...", + # "ref": "master", + # "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83", + # "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50" + # } + # + get ":id/repository/files" do + required_attributes! [:file_path, :ref] + attrs = attributes_for_keys [:file_path, :ref] + ref = attrs.delete(:ref) + file_path = attrs.delete(:file_path) + + commit = user_project.repository.commit(ref) + not_found! "Commit" unless commit + + blob = user_project.repository.blob_at(commit.sha, file_path) + + if blob + status(200) + + { + file_name: blob.name, + file_path: blob.path, + size: blob.size, + encoding: "base64", + content: Base64.encode64(blob.data), + ref: ref, + blob_id: blob.id, + commit_id: commit.id, + } + else + render_api_error!('File not found', 404) + end + end + # Create new file in repository # # Parameters: - # file_path (optional) - The path to new file. Ex. lib/class.rb + # file_path (required) - The path to new file. Ex. lib/class.rb # branch_name (required) - The name of branch # content (required) - File content # commit_message (required) - Commit message |