Commit 29d9a1fb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-repo-path' into 'master'

Fix repository name/path extraction for GitlabUpdate

See merge request !34
parents 59bffe6b b6ec27d9
...@@ -3,3 +3,4 @@ tmp/* ...@@ -3,3 +3,4 @@ tmp/*
*.log *.log
/*.log.* /*.log.*
authorized_keys.lock authorized_keys.lock
coverage/
require_relative 'gitlab_init' require_relative 'gitlab_init'
require_relative 'gitlab_net' require_relative 'gitlab_net'
require_relative 'names_helper'
require 'json' require 'json'
class GitlabUpdate class GitlabUpdate
attr_reader :config include NamesHelper
attr_reader :config, :repo_path, :repo_name,
:ref, :ref_name, :oldrev, :newrev
def initialize(repo_path, actor, ref) def initialize(repo_path, actor, ref)
@config = GitlabConfig.new @config = GitlabConfig.new
@repo_path, @actor, @ref = repo_path.strip, actor, ref
@repo_path = repo_path.strip @repo_name = extract_repo_name(@repo_path.dup, config.repos_path.to_s)
@repo_name = @repo_path @ref_name = extract_ref_name(ref)
@repo_name.gsub!(config.repos_path.to_s, "")
@repo_name.gsub!(/\.git$/, "")
@repo_name.gsub!(/^\//, "")
@actor = actor
@ref = ref
@ref_name = ref.gsub(/\Arefs\/(tags|heads)\//, '')
@oldrev = ARGV[1] @oldrev = ARGV[1]
@newrev = ARGV[2] @newrev = ARGV[2]
end end
......
module NamesHelper
def extract_repo_name(path, base)
repo_name = path.strip
repo_name.gsub!(base, "")
repo_name.gsub!(/\.git$/, "")
repo_name.gsub!(/^\//, "")
repo_name
end
def extract_ref_name(ref)
ref.gsub(/\Arefs\/(tags|heads)\//, '')
end
end
require 'spec_helper'
require 'gitlab_update'
describe GitlabUpdate do
let(:repository_path) { "/home/git/repositories" }
let(:repo_name) { 'dzaporozhets/gitlab-ci' }
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:ref) { 'refs/heads/awesome-feature' }
let(:gitlab_update) { GitlabUpdate.new(repo_path, 'key-123', ref) }
before do
ARGV[1] = 'd1e3ca3b25'
ARGV[2] = 'c2b3653b25'
GitlabConfig.any_instance.stub(repos_path: repository_path)
end
describe :initialize do
it { gitlab_update.repo_name.should == repo_name }
it { gitlab_update.repo_path.should == repo_path }
it { gitlab_update.ref.should == ref }
it { gitlab_update.ref_name.should == 'awesome-feature' }
it { gitlab_update.oldrev.should == 'd1e3ca3b25' }
it { gitlab_update.newrev.should == 'c2b3653b25' }
end
end
require 'spec_helper'
require 'gitlab_update'
describe NamesHelper do
include NamesHelper
describe :extract_repo_name do
it { extract_repo_name(' /opt/repos/randx/gitlab.git', '/opt/repos').should == 'randx/gitlab' }
it { extract_repo_name("/opt/repos/randx/gitlab.git\r\n", '/opt/repos/').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' }
it { extract_ref_name('refs/tags/releases/v2.2.1').should == 'releases/v2.2.1' }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment