Workhorse to serve email diffs

Depends on the changes in Workhorse (gitlab-org/gitlab-workhorse!48).
This commit is contained in:
Z.J. van de Weg 2016-06-10 14:57:50 +02:00
parent e0e325625e
commit c31f876a27
5 changed files with 24 additions and 23 deletions

View file

@ -4,6 +4,7 @@ v 8.10.0 (unreleased)
- Replace Haml with Hamlit to make view rendering faster. !3666
- Wrap code blocks on Activies and Todos page. !4783 (winniehell)
- Add Sidekiq queue duration to transaction metrics.
- Let Workhorse serve format-patch diffs
- Make images fit to the size of the viewport !4810
- Fix check for New Branch button on Issue page !4630 (winniehell)
- Fix MR-auto-close text added to description. !4836

View file

@ -59,7 +59,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format|
format.html
format.json { render json: @merge_request }
format.patch { render text: @merge_request.to_patch }
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
end
format.diff do
return render_404 unless @merge_request.diff_refs

View file

@ -319,13 +319,6 @@ class MergeRequest < ActiveRecord::Base
)
end
# Returns the commit as a series of email patches.
#
# see "git format-patch"
def to_patch
target_project.repository.format_patch(diff_base_commit.sha, source_sha)
end
def hook_attrs
attrs = {
source: source_project.try(:hook_attrs),

View file

@ -52,6 +52,19 @@ module Gitlab
]
end
def send_git_patch(repository, from, to)
params = {
'RepoPath' => repository.path_to_repo,
'ShaFrom' => from,
'ShaTo' => to
}
[
SEND_DATA_HEADER,
"git-format-patch:#{encode(params)}"
]
end
protected
def encode(hash)

View file

@ -96,26 +96,14 @@ describe Projects::MergeRequestsController do
end
describe "as patch" do
include_examples "export merge as", :patch
let(:format) { :patch }
it "should really be a git email patch with commit" do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid, format: format)
expect(response.body[0..100]).to start_with("From #{merge_request.commits.last.id}")
end
it "should contain git diffs" do
it 'triggers workhorse to serve the request' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: format)
format: :patch)
expect(response.body).to match(/^diff --git/)
expect(response.headers['Gitlab-Workhorse-Send-Data']).to start_with("git-format-patch:")
end
end
end