Add send_git_patch helper

This commit is contained in:
Douwe Maan 2016-07-03 17:01:13 -04:00
parent 5ffb848ee6
commit ddec2ed0df
4 changed files with 22 additions and 12 deletions

View file

@ -58,14 +58,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format|
format.html
format.json { render json: @merge_request }
format.patch do
headers.store(*Gitlab::Workhorse.send_git_patch(@project.repository,
@merge_request.diff_base_commit.id,
@merge_request.last_commit.id))
headers['Content-Disposition'] = 'inline'
head :ok
format.json do
render json: @merge_request
end
format.patch do
return render_404 unless @merge_request.diff_refs
send_git_patch @project.repository, @merge_request.diff_refs
end
format.diff do
return render_404 unless @merge_request.diff_refs

View file

@ -1,4 +1,4 @@
# Helpers to send Git blobs, diffs or archives through Workhorse.
# Helpers to send Git blobs, diffs, patches or archives through Workhorse.
# Workhorse will also serve files when using `send_file`.
module WorkhorseHelper
# Send a Git blob through Workhorse
@ -16,6 +16,13 @@ module WorkhorseHelper
head :ok
end
# Send a Git patch through Workhorse
def send_git_patch(repository, diff_refs)
headers.store(*Gitlab::Workhorse.send_git_patch(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))

View file

@ -50,11 +50,11 @@ module Gitlab
]
end
def send_git_patch(repository, from, to)
def send_git_patch(repository, diff_refs)
params = {
'RepoPath' => repository.path_to_repo,
'ShaFrom' => from,
'ShaTo' => to
'ShaFrom' => diff_refs.start_sha,
'ShaTo' => diff_refs.head_sha
}
[

View file

@ -103,7 +103,7 @@ describe Projects::MergeRequestsController do
id: merge_request.iid,
format: :patch)
expect(response.headers['Gitlab-Workhorse-Send-Data']).to start_with("git-format-patch:")
expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-format-patch:")
end
end
end