summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-05-03 18:07:54 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-05-05 10:52:06 -0300
commit8bc381db90c92bca6ba868d1588af1ad1a41073b (patch)
treee10f3f04f40493315b02938b7a7726537072b968
parent5249157552bbf4cbf279b1decbd4a0e90e056077 (diff)
downloadgitlab-ce-8bc381db90c92bca6ba868d1588af1ad1a41073b.tar.gz
-rw-r--r--app/controllers/projects/git_http_controller.rb2
-rw-r--r--app/workers/post_receive.rb7
-rw-r--r--lib/api/internal.rb2
-rw-r--r--lib/gitlab/gl_repository.rb4
-rw-r--r--lib/gitlab/workhorse.rb6
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb17
6 files changed, 32 insertions, 6 deletions
diff --git a/app/controllers/projects/git_http_controller.rb b/app/controllers/projects/git_http_controller.rb
index 10adddb4636..9e4edcae101 100644
--- a/app/controllers/projects/git_http_controller.rb
+++ b/app/controllers/projects/git_http_controller.rb
@@ -59,7 +59,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController
def render_ok
set_workhorse_internal_api_content_type
- render json: Gitlab::Workhorse.git_http_ok(repository, user, action_name)
+ render json: Gitlab::Workhorse.git_http_ok(repository, wiki?, user, action_name)
end
def render_http_not_allowed
diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb
index 39f03983821..127d8dfbb61 100644
--- a/app/workers/post_receive.rb
+++ b/app/workers/post_receive.rb
@@ -44,6 +44,13 @@ class PostReceive
private
+ # To maintain backwards compatibility, we accept both gl_repository or
+ # repository paths as project identifiers. Our plan is to migrate to
+ # gl_repository only with the following plan:
+ # 9.2: Handle both possible values. Keep Gitlab-Shell sending only repo paths
+ # 9.3 (or patch release): Make GitLab Shell pass gl_repository if present
+ # 9.4 (or patch release): Make GitLab Shell always pass gl_repository
+ # 9.5 (or patch release): Handle only gl_repository as project identifier on this method
def parse_project_identifier(project_identifier)
if project_identifier.start_with?('/')
Gitlab::RepoPath.parse(project_identifier)
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index ddb2047f686..2a11790b215 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -44,7 +44,7 @@ module API
# Project id to pass between components that don't share/don't have
# access to the same filesystem mounts
- response[:gl_repository] = "#{wiki? ? 'wiki' : 'project'}-#{project.id}"
+ response[:gl_repository] = Gitlab::GlRepository.gl_repository(project, wiki?)
# Return the repository full path so that gitlab-shell has it when
# handling ssh commands
diff --git a/lib/gitlab/gl_repository.rb b/lib/gitlab/gl_repository.rb
index 6997546049e..07c0abcce23 100644
--- a/lib/gitlab/gl_repository.rb
+++ b/lib/gitlab/gl_repository.rb
@@ -1,5 +1,9 @@
module Gitlab
module GlRepository
+ def self.gl_repository(project, is_wiki)
+ "#{is_wiki ? 'wiki' : 'project'}-#{project.id}"
+ end
+
def self.parse(gl_repository)
match_data = /\A(project|wiki)-([1-9][0-9]*)\z/.match(gl_repository)
unless match_data
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index c551f939df1..8c5ad01e8c2 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -16,15 +16,17 @@ module Gitlab
SECRET_LENGTH = 32
class << self
- def git_http_ok(repository, user, action)
+ def git_http_ok(repository, is_wiki, user, action)
+ project = repository.project
repo_path = repository.path_to_repo
params = {
GL_ID: Gitlab::GlId.gl_id(user),
+ GL_REPOSITORY: Gitlab::GlRepository.gl_repository(project, is_wiki),
RepoPath: repo_path,
}
if Gitlab.config.gitaly.enabled
- address = Gitlab::GitalyClient.get_address(repository.project.repository_storage)
+ address = Gitlab::GitalyClient.get_address(project.repository_storage)
params[:Repository] = repository.gitaly_repository.to_h
feature_enabled = case action.to_s
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index b703e9808a8..beb1791a429 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -181,10 +181,23 @@ describe Gitlab::Workhorse, lib: true do
let(:user) { create(:user) }
let(:repo_path) { repository.path_to_repo }
let(:action) { 'info_refs' }
+ let(:params) do
+ { GL_ID: "user-#{user.id}", GL_REPOSITORY: "project-#{project.id}", RepoPath: repo_path }
+ end
+
+ subject { described_class.git_http_ok(repository, false, user, action) }
+
+ it { expect(subject).to include(params) }
- subject { described_class.git_http_ok(repository, user, action) }
+ context 'when is_wiki' do
+ let(:params) do
+ { GL_ID: "user-#{user.id}", GL_REPOSITORY: "wiki-#{project.id}", RepoPath: repo_path }
+ end
+
+ subject { described_class.git_http_ok(repository, true, user, action) }
- it { expect(subject).to include({ GL_ID: "user-#{user.id}", RepoPath: repo_path }) }
+ it { expect(subject).to include(params) }
+ end
context 'when Gitaly is enabled' do
let(:gitaly_params) do