lib/gl.rb in gl-0.2.0 vs lib/gl.rb in gl-0.2.1

- old
+ new

@@ -25,20 +25,27 @@ def self.open_in_browser(url) url = "#{Gitlab.endpoint.gsub('api/v4', '')}#{url}" `sensible-browser #{url}` end + def self.validate_endpoint! + return if Net::HTTP.get(URI("#{Gitlab.endpoint}version")) == '{"message":"401 Unauthorized"}' + + puts 'It seems this is not a valid GitLab repository' + exit(1) + end + def self.remote_url `git config --get remote.origin.url`.chomp end def self.remote_parse if remote_url.start_with?('git@') - regexp = %r{(git@|https:\/\/|ssh:\/\/)(.*?)(:|\/)(.*)?(\.git)} + regexp = %r{git@(.*?)(:|\/)(.*)?(\.git)} url = remote_url - host = url.gsub(regexp, '\2') - project = url.gsub(regexp, '\4') + host = url.gsub(regexp, '\1') + project = url.gsub(regexp, '\3') else uri = URI(remote_url) host = uri.host project = uri.path.gsub(%r{\/(.*)\.git$}, '\1') end