debian-mirror-gitlab/lib/gitlab/workhorse.rb

63 lines
1.3 KiB
Ruby
Raw Normal View History

2016-04-02 18:10:28 +05:30
require 'base64'
require 'json'
module Gitlab
class Workhorse
2016-06-02 11:05:42 +05:30
SEND_DATA_HEADER = 'Gitlab-Workhorse-Send-Data'
2016-04-02 18:10:28 +05:30
class << self
def git_http_ok(repository, user)
{
'GL_ID' => Gitlab::GlId.gl_id(user),
'RepoPath' => repository.path_to_repo,
}
end
2016-04-02 18:10:28 +05:30
def send_git_blob(repository, blob)
2016-06-02 11:05:42 +05:30
params = {
2016-04-02 18:10:28 +05:30
'RepoPath' => repository.path_to_repo,
'BlobId' => blob.id,
}
[
2016-06-02 11:05:42 +05:30
SEND_DATA_HEADER,
"git-blob:#{encode(params)}"
2016-04-02 18:10:28 +05:30
]
end
2016-06-02 11:05:42 +05:30
def send_git_archive(repository, ref:, format:)
2016-06-02 11:05:42 +05:30
format ||= 'tar.gz'
format.downcase!
params = repository.archive_metadata(ref, Gitlab.config.gitlab.repository_downloads_path, format)
2016-06-02 11:05:42 +05:30
raise "Repository or ref not found" if params.empty?
[
SEND_DATA_HEADER,
"git-archive:#{encode(params)}"
2016-06-02 11:05:42 +05:30
]
end
def send_git_diff(repository, diff_refs)
from, to = diff_refs
params = {
'RepoPath' => repository.path_to_repo,
'ShaFrom' => from.sha,
'ShaTo' => to.sha
}
[
SEND_DATA_HEADER,
"git-diff:#{encode(params)}"
]
end
2016-06-02 11:05:42 +05:30
protected
2016-06-02 11:05:42 +05:30
def encode(hash)
Base64.urlsafe_encode64(JSON.dump(hash))
end
2016-04-02 18:10:28 +05:30
end
end
end