diff options
| author | Nihad Abbasov <mail@narkoz.me> | 2012-07-31 23:37:48 -0700 |
|---|---|---|
| committer | Nihad Abbasov <mail@narkoz.me> | 2012-07-31 23:37:48 -0700 |
| commit | d63706d72c8a52625bf1e892484261378936e240 (patch) | |
| tree | df9d5735ce84993c9ece02769ce8c02fc2d5aa3e /lib/api/projects.rb | |
| parent | 5926bbac12d5831e1ad90964272b96e152a72e34 (diff) | |
| parent | ce837f3d1bbacd3dc9e9171d66f3cf5ed3317c7f (diff) | |
| download | gitlab-ce-d63706d72c8a52625bf1e892484261378936e240.tar.gz | |
Merge pull request #1157 from CodeAdept/api_blob_contents
API blob contents
Diffstat (limited to 'lib/api/projects.rb')
| -rw-r--r-- | lib/api/projects.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 8edfa481c10..0341facf9f8 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -33,6 +33,18 @@ module Gitlab present user_project.repo.heads.sort_by(&:name), :with => Entities::RepoObject end + # Get a single branch + # + # Parameters: + # id (required) - The ID or code name of a project + # branch_id (required) - The name of the branch + # Example Request: + # GET /projects/:id/repository/branches/:branch_id + get ":id/repository/branches/:branch_id" do + @branch = user_project.repo.heads.find { |item| item.name == params[:branch_id] } + present @branch, :with => Entities::RepoObject + end + # Get a project repository tags # # Parameters: @@ -131,6 +143,34 @@ module Gitlab @snippet = user_project.snippets.find(params[:snippet_id]) present @snippet.content end + + # Get a raw file contents + # + # Parameters: + # id (required) - The ID or code name of a project + # sha (required) - The commit or branch name + # filepath (required) - The path to the file to display + # Example Request: + # GET /projects/:id/repository/commits/:sha/blob + get ":id/repository/commits/:sha/blob" do + ref = params[:sha] + + commit = user_project.commit ref + error!('404 Commit Not Found', 404) unless commit + + tree = Tree.new commit.tree, user_project, ref, params[:filepath] + error!('404 File Not Found', 404) unless tree.try(:tree) + + if tree.text? + encoding = Gitlab::Encode.detect_encoding(tree.data) + content_type encoding ? "text/plain; charset=#{encoding}" : "text/plain" + else + content_type tree.mime_type + end + + present tree.data + end + end end end |
