diff --git a/lib/ors/config.rb b/lib/ors/config.rb index be99389..8726bbd 100644 --- a/lib/ors/config.rb +++ b/lib/ors/config.rb @@ -58,7 +58,7 @@ def git private def name_from_git - git.config["remote.origin.url"].gsub /.*?:(.*?).git/, '\1' + git.config["remote.origin.url"].gsub(/^[\w]*(@|:\/\/)[^\/:]*(\/|:)([a-zA-Z0-9\/]*)(.git)?$/i, '\3') end end diff --git a/spec/ors/config_spec.rb b/spec/ors/config_spec.rb index 49ca794..e508462 100644 --- a/spec/ors/config_spec.rb +++ b/spec/ors/config_spec.rb @@ -97,4 +97,21 @@ class ORS::ConfigTest; include ORS::Config; end end end + context "#name_from_git" do + { + "git://github.com/testing/github.git" => "testing/github", + "git://example.com/testing/gitlabhq.git" => "testing/gitlabhq", + "git://github.com/testing/github" => "testing/github", + "git@github.com:testing/github" => "testing/github", + "git@ghub.com:testing/gitlabhq.git" => "testing/gitlabhq", + "git@ghub.com:gitlabhq.git" => "gitlabhq", + "git://ghub.com/gitlabhq.git" => "gitlabhq" + }.each do |remote, name| + it "should handle a remote origin url such as #{remote}" do + mock(ORS::Config).git { mock!.config { {"remote.origin.url" => remote} }} + ORS::Config.send(:name_from_git).should == name + end + end + end + end