summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-27 12:34:23 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-27 16:57:57 +0300
commit00bf30ba9f5831e74b6990d4179bd6e4c0ce072a (patch)
treee55c08dafc6d0a6100aa1a3bbb49433e77699339
parenteae98b679b775454c630440b93f41dfdc8b1f72d (diff)
downloadgitlab-shell-00bf30ba9f5831e74b6990d4179bd6e4c0ce072a.tar.gz
Use full repository path for API calls instead of extracting namedz-support-nested-namespaces
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--CHANGELOG3
-rw-r--r--lib/gitlab_access.rb5
-rw-r--r--lib/gitlab_net.rb14
-rw-r--r--lib/gitlab_post_receive.rb3
-rw-r--r--lib/names_helper.rb7
-rw-r--r--spec/gitlab_access_spec.rb1
-rw-r--r--spec/gitlab_post_receive_spec.rb8
-rw-r--r--spec/names_helper_spec.rb5
8 files changed, 16 insertions, 30 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 0e96dc5..30fb166 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v4.0.0
+ - Use full repository path for API calls
+
v3.6.6
- Re-use the default logger when logging metrics data
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb
index 04806b2..ab431bf 100644
--- a/lib/gitlab_access.rb
+++ b/lib/gitlab_access.rb
@@ -9,19 +9,18 @@ class GitlabAccess
include NamesHelper
- attr_reader :config, :repo_path, :repo_name, :changes, :protocol
+ attr_reader :config, :repo_path, :changes, :protocol
def initialize(repo_path, actor, changes, protocol)
@config = GitlabConfig.new
@repo_path = repo_path.strip
@actor = actor
- @repo_name = extract_repo_name(@repo_path.dup)
@changes = changes.lines
@protocol = protocol
end
def exec
- status = api.check_access('git-receive-pack', @repo_name, @actor, @changes, @protocol)
+ status = api.check_access('git-receive-pack', @repo_path, @actor, @changes, @protocol)
raise AccessDeniedError, status.message unless status.allowed?
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 994f8d5..ed0b705 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -21,7 +21,7 @@ class GitlabNet
params = {
action: cmd,
changes: changes,
- project: project_name(repo),
+ project: sanitize_path(repo),
protocol: protocol
}
@@ -49,7 +49,7 @@ class GitlabNet
def lfs_authenticate(key, repo)
params = {
- project: project_name(repo),
+ project: sanitize_path(repo),
key_id: key.gsub('key-', '')
}
@@ -65,10 +65,10 @@ class GitlabNet
JSON.parse(resp.body) rescue {}
end
- def merge_request_urls(repo_name, changes)
+ def merge_request_urls(repo_path, changes)
changes = changes.join("\n") unless changes.kind_of?(String)
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
- resp = get("#{host}/merge_request_urls?project=#{URI.escape(repo_name)}&changes=#{URI.escape(changes)}")
+ resp = get("#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}")
JSON.parse(resp.body) rescue []
end
@@ -118,10 +118,8 @@ class GitlabNet
protected
- def project_name(repo)
- project_name = repo.gsub("'", "")
- project_name = project_name.gsub(/\.git\Z/, "")
- project_name.gsub(/\A\//, "")
+ def sanitize_path(repo)
+ repo.gsub("'", "")
end
def config
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index 9ad74f5..3af2b38 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -13,7 +13,6 @@ class GitlabPostReceive
def initialize(repo_path, actor, changes)
@config = GitlabConfig.new
@repo_path, @actor = repo_path.strip, actor
- @repo_name = extract_repo_name(@repo_path.dup)
@changes = changes
@jid = SecureRandom.hex(12)
end
@@ -29,7 +28,7 @@ class GitlabPostReceive
print_broadcast_message(broadcast_message["message"])
end
- merge_request_urls = api.merge_request_urls(@repo_name, @changes)
+ merge_request_urls = api.merge_request_urls(@repo_path, @changes)
print_merge_request_links(merge_request_urls)
rescue GitlabNet::ApiUnreachableError
nil
diff --git a/lib/names_helper.rb b/lib/names_helper.rb
index ec41b79..1f9c56e 100644
--- a/lib/names_helper.rb
+++ b/lib/names_helper.rb
@@ -1,11 +1,4 @@
module NamesHelper
- def extract_repo_name(path)
- repo_name = path.strip
- repo_name.gsub!(/\.git$/, "")
- repo_name.gsub!(/^\//, "")
- repo_name.split(File::SEPARATOR).last(2).join(File::SEPARATOR)
- end
-
def extract_ref_name(ref)
ref.gsub(/\Arefs\/(tags|heads)\//, '')
end
diff --git a/spec/gitlab_access_spec.rb b/spec/gitlab_access_spec.rb
index 2781aa9..a602883 100644
--- a/spec/gitlab_access_spec.rb
+++ b/spec/gitlab_access_spec.rb
@@ -22,7 +22,6 @@ describe GitlabAccess do
end
describe :initialize do
- it { subject.repo_name.should == repo_name }
it { subject.repo_path.should == repo_path }
it { subject.changes.should == ['wow'] }
it { subject.protocol.should == 'ssh' }
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb
index db1e776..bac6f97 100644
--- a/spec/gitlab_post_receive_spec.rb
+++ b/spec/gitlab_post_receive_spec.rb
@@ -18,7 +18,7 @@ describe GitlabPostReceive do
before do
GitlabConfig.any_instance.stub(repos_path: repository_path)
GitlabNet.any_instance.stub(broadcast_message: { })
- GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) { [] }
+ GitlabNet.any_instance.stub(:merge_request_urls).with(repo_path, wrongly_encoded_changes) { [] }
expect(Time).to receive(:now).and_return(enqueued_at)
end
@@ -35,7 +35,7 @@ describe GitlabPostReceive do
context 'Without broad cast message' do
context 'pushing new branch' do
before do
- GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) do
+ GitlabNet.any_instance.stub(:merge_request_urls).with(repo_path, wrongly_encoded_changes) do
[{
"branch_name" => "new_branch",
"url" => "http://localhost/dzaporozhets/gitlab-ci/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch",
@@ -62,7 +62,7 @@ describe GitlabPostReceive do
context 'pushing existing branch with merge request created' do
before do
- GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) do
+ GitlabNet.any_instance.stub(:merge_request_urls).with(repo_path, wrongly_encoded_changes) do
[{
"branch_name" => "feature_branch",
"url" => "http://localhost/dzaporozhets/gitlab-ci/merge_requests/1",
@@ -90,7 +90,7 @@ describe GitlabPostReceive do
context 'show broadcast message and merge request link' do
before do
- GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) do
+ GitlabNet.any_instance.stub(:merge_request_urls).with(repo_path, wrongly_encoded_changes) do
[{
"branch_name" => "new_branch",
"url" => "http://localhost/dzaporozhets/gitlab-ci/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch",
diff --git a/spec/names_helper_spec.rb b/spec/names_helper_spec.rb
index a5fcf94..f2a95e5 100644
--- a/spec/names_helper_spec.rb
+++ b/spec/names_helper_spec.rb
@@ -4,11 +4,6 @@ require 'names_helper'
describe NamesHelper do
include NamesHelper
- describe :extract_repo_name do
- it { extract_repo_name(' /opt/repos/randx/gitlab.git').should == 'randx/gitlab' }
- it { extract_repo_name("/opt/repos/randx/gitlab.git\r\n").should == 'randx/gitlab' }
- end
-
describe :extract_ref_name do
it { extract_ref_name('refs/heads/awesome-feature').should == 'awesome-feature' }
it { extract_ref_name('refs/tags/v2.2.1').should == 'v2.2.1' }