From 27912f9c21c3dfb20f8d1d037f8c085281de5b0e Mon Sep 17 00:00:00 2001 From: Thom Gerdes Date: Mon, 23 Dec 2013 01:37:38 -0800 Subject: [PATCH 1/2] Add api support for raw blob search See issue http://feedback.gitlab.com/forums/176466-general/suggestions/4566001-expose-raw-object-search-via-the-gitlab-api --- doc/api/repositories.md | 18 ++++++++++++++++-- lib/api/repositories.rb | 22 ++++++++++++++++++++++ spec/requests/api/repositories_spec.rb | 7 +++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/doc/api/repositories.md b/doc/api/repositories.md index af7b82ca76d..6b3a43b869e 100644 --- a/doc/api/repositories.md +++ b/doc/api/repositories.md @@ -343,9 +343,9 @@ Parameters: ``` -## Raw blob content +## Raw file content -Get the raw file contents for a file. +Get the raw file contents for a file by commit sha and path. ``` GET /projects/:id/repository/blobs/:sha @@ -358,6 +358,20 @@ Parameters: + `filepath` (required) - The path the file +## Raw blob content + +Get the raw file contents for a blob by blob sha. + +``` +GET /projects/:id/repository/raw_blobs/:sha +``` + +Parameters: + ++ `id` (required) - The ID of a project ++ `sha` (required) - The blob sha + + ## Get file archive Get a an archive of the repository diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index c9422fdb165..6a9dc9a39f1 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -177,6 +177,28 @@ module API present blob.data end + # Get a raw blob contents by blob sha + # + # Parameters: + # id (required) - The ID of a project + # sha (required) - The blob's sha + # Example Request: + # GET /projects/:id/repository/raw_blobs/:sha + get ":id/repository/raw_blobs/:sha" do + ref = params[:sha] + + repo = user_project.repository + + blob = Gitlab::Git::Blob.raw(repo, ref) + + not_found! "Blob" unless blob + + env['api.format'] = :txt + + content_type blob.mime_type + present blob.data + end + # Get a an archive of the repository # # Parameters: diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 9649c4d09c8..e078efcc50a 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -225,6 +225,13 @@ describe API::API do end end + describe "GET /projects/:id/repository/raw_blobs/:sha" do + it "should get the raw file contents" do + get api("/projects/#{project.id}/repository/raw_blobs/d1aff2896d99d7acc4d9780fbb716b113c45ecf7", user) + response.status.should == 200 + end + end + describe "GET /projects/:id/repository/archive/:sha" do it "should get the archive" do get api("/projects/#{project.id}/repository/archive", user) From 498ec08da3a7dae92b317e838689e73935fcb38a Mon Sep 17 00:00:00 2001 From: xyb Date: Fri, 27 Dec 2013 19:38:29 +0800 Subject: [PATCH 2/2] Force IE use latest engine to render. --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c398593c5f6..0e714dbfcdf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -160,6 +160,7 @@ class ApplicationController < ActionController::Base def default_headers headers['X-Frame-Options'] = 'DENY' headers['X-XSS-Protection'] = '1; mode=block' + headers['X-UA-Compatible'] = 'IE=edge' end def add_gon_variables