diff options
author | Robert Speicher <robert@gitlab.com> | 2016-06-10 16:21:26 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-06-10 16:21:26 +0000 |
commit | 37be2007f9aa6197c1304a450110aecbde5434f9 (patch) | |
tree | 63e12aaae7dad8a962141b78542431083aea23dd /app | |
parent | d6de816982eb9a227a384c3318d050a23ad18529 (diff) | |
parent | 701e2df7e55113dafd48c570baad44bf7f24f863 (diff) | |
download | gitlab-ce-37be2007f9aa6197c1304a450110aecbde5434f9.tar.gz |
Merge branch 'workhorse-helpers' into 'master'
Add workhorse controller and API helpers
Adds `send_git_blob` and `send_git_archive` controller and API helpers to reduce duplication and make Workhorse easier for a developer to work with.
See merge request !4486
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/projects/avatars_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/projects/raw_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/projects/repositories_controller.rb | 3 | ||||
-rw-r--r-- | app/helpers/workhorse_helper.rb | 24 |
6 files changed, 30 insertions, 15 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 62f63701799..cd6ae507cf1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base include Gitlab::GonHelper include GitlabRoutingHelper include PageLayoutHelper + include WorkhorseHelper before_action :authenticate_user_from_token! before_action :authenticate_user! diff --git a/app/controllers/projects/avatars_controller.rb b/app/controllers/projects/avatars_controller.rb index 72921b3aa14..5962f74c39b 100644 --- a/app/controllers/projects/avatars_controller.rb +++ b/app/controllers/projects/avatars_controller.rb @@ -10,10 +10,7 @@ class Projects::AvatarsController < Projects::ApplicationController return if cached_blob? - headers.store(*Gitlab::Workhorse.send_git_blob(@repository, @blob)) - headers['Content-Disposition'] = 'inline' - headers['Content-Type'] = safe_content_type(@blob) - head :ok # 'render nothing: true' messes up the Content-Type + send_git_blob @repository, @blob else render_404 end diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 06a114dcbe8..67e7187c10d 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -61,12 +61,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController format.json { render json: @merge_request } format.patch { render text: @merge_request.to_patch } format.diff do - headers.store(*Gitlab::Workhorse.send_git_diff(@project.repository, - @merge_request.diff_base_commit.id, - @merge_request.last_commit.id)) - headers['Content-Disposition'] = 'inline' + return render_404 unless @merge_request.diff_refs - head :ok + send_git_diff @project.repository, @merge_request.diff_refs end end end diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb index 10de0e60530..10d24da16d7 100644 --- a/app/controllers/projects/raw_controller.rb +++ b/app/controllers/projects/raw_controller.rb @@ -18,10 +18,7 @@ class Projects::RawController < Projects::ApplicationController if @blob.lfs_pointer? send_lfs_object else - headers.store(*Gitlab::Workhorse.send_git_blob(@repository, @blob)) - headers['Content-Disposition'] = 'inline' - headers['Content-Type'] = safe_content_type(@blob) - head :ok # 'render nothing: true' messes up the Content-Type + send_git_blob @repository, @blob end else render_404 diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb index bb7a6b6a5ab..d5af0341d18 100644 --- a/app/controllers/projects/repositories_controller.rb +++ b/app/controllers/projects/repositories_controller.rb @@ -11,8 +11,7 @@ class Projects::RepositoriesController < Projects::ApplicationController end def archive - headers.store(*Gitlab::Workhorse.send_git_archive(@project, params[:ref], params[:format])) - head :ok + send_git_archive @repository, ref: params[:ref], format: params[:format] rescue => ex logger.error("#{self.class.name}: #{ex}") return git_not_found! diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb new file mode 100644 index 00000000000..2bd0dbfd095 --- /dev/null +++ b/app/helpers/workhorse_helper.rb @@ -0,0 +1,24 @@ +# Helpers to send Git blobs, diffs or archives through Workhorse. +# Workhorse will also serve files when using `send_file`. +module WorkhorseHelper + # Send a Git blob through Workhorse + def send_git_blob(repository, blob) + headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob)) + headers['Content-Disposition'] = 'inline' + headers['Content-Type'] = safe_content_type(blob) + head :ok # 'render nothing: true' messes up the Content-Type + end + + # Send a Git diff through Workhorse + def send_git_diff(repository, diff_refs) + headers.store(*Gitlab::Workhorse.send_git_diff(repository, diff_refs)) + headers['Content-Disposition'] = 'inline' + head :ok + end + + # Archive a Git repository and send it through Workhorse + def send_git_archive(repository, ref:, format:) + headers.store(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format)) + head :ok + end +end |