summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-06-10 16:21:26 +0000
committerRobert Speicher <robert@gitlab.com>2016-06-10 16:21:26 +0000
commit37be2007f9aa6197c1304a450110aecbde5434f9 (patch)
tree63e12aaae7dad8a962141b78542431083aea23dd /lib
parentd6de816982eb9a227a384c3318d050a23ad18529 (diff)
parent701e2df7e55113dafd48c570baad44bf7f24f863 (diff)
downloadgitlab-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 'lib')
-rw-r--r--lib/api/helpers.rb10
-rw-r--r--lib/api/repositories.rb10
-rw-r--r--lib/gitlab/workhorse.rb18
3 files changed, 23 insertions, 15 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 2aaa0557ea3..e1d3bbcc02d 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -408,5 +408,15 @@ module API
error!(errors[:access_level], 422) if errors[:access_level].any?
not_found!(errors)
end
+
+ def send_git_blob(repository, blob)
+ env['api.format'] = :txt
+ content_type 'text/plain'
+ header(*Gitlab::Workhorse.send_git_blob(repository, blob))
+ end
+
+ def send_git_archive(repository, ref:, format:)
+ header(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format))
+ end
end
end
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 9cb14e95ebc..f55aceed92c 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -56,8 +56,7 @@ module API
blob = Gitlab::Git::Blob.find(repo, commit.id, params[:filepath])
not_found! "File" unless blob
- content_type 'text/plain'
- header(*Gitlab::Workhorse.send_git_blob(repo, blob))
+ send_git_blob repo, blob
end
# Get a raw blob contents by blob sha
@@ -80,10 +79,7 @@ module API
not_found! 'Blob' unless blob
- env['api.format'] = :txt
-
- content_type blob.mime_type
- header(*Gitlab::Workhorse.send_git_blob(repo, blob))
+ send_git_blob repo, blob
end
# Get a an archive of the repository
@@ -98,7 +94,7 @@ module API
authorize! :download_code, user_project
begin
- header(*Gitlab::Workhorse.send_git_archive(user_project, params[:sha], params[:format]))
+ send_git_archive user_project.repository, ref: params[:sha], format: params[:format]
rescue
not_found!('File')
end
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index 56af739b1ef..388f84dbe0e 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -21,27 +21,29 @@ module Gitlab
[
SEND_DATA_HEADER,
- "git-blob:#{encode(params)}",
+ "git-blob:#{encode(params)}"
]
end
- def send_git_archive(project, ref, format)
+ def send_git_archive(repository, ref:, format:)
format ||= 'tar.gz'
format.downcase!
- params = project.repository.archive_metadata(ref, Gitlab.config.gitlab.repository_downloads_path, format)
+ params = repository.archive_metadata(ref, Gitlab.config.gitlab.repository_downloads_path, format)
raise "Repository or ref not found" if params.empty?
[
SEND_DATA_HEADER,
- "git-archive:#{encode(params)}",
+ "git-archive:#{encode(params)}"
]
end
- def send_git_diff(repository, from, to)
+ def send_git_diff(repository, diff_refs)
+ from, to = diff_refs
+
params = {
- 'RepoPath' => repository.path_to_repo,
- 'ShaFrom' => from,
- 'ShaTo' => to
+ 'RepoPath' => repository.path_to_repo,
+ 'ShaFrom' => from.sha,
+ 'ShaTo' => to.sha
}
[