Sha256: 712d164438f24adde21a2cf0d7b09d64427037e92124d874a5c8ba6c5d35978b

Contents?: true

Size: 1.32 KB

Versions: 37

Compression:

Stored size: 1.32 KB

Contents

module OhlohScm::Adapters
	class GitAdapter < AbstractAdapter
		def self.url_regex
			/^(http|https|rsync|git|ssh):\/\/(\w+@)?[A-Za-z0-9_\-\.]+(:\d+)?\/[A-Za-z0-9_@\-\.\/\~\+]*$/
		end

		def self.public_url_regex
			/^(http|https|git):\/\/(\w+@)?[A-Za-z0-9_\-\.]+(:\d+)?\/[A-Za-z0-9_\-\.\/\~\+]*$/
		end

		def normalize
			super
      @url = normalize_url
			@branch_name = 'master' if @branch_name.to_s == ''
			self
		end

    # Given a Github read-write URL, return a git protocol read-only URL
    # Given a Github web URL, return a git protocol read-only URL
    # Given a Git read-write protocol URL, return a git protocol read-only URL
    # Else, return the URL
    def normalize_url
      case @url
      when /^https?:\/\/\w+@github.com\/(.+)\.git$/
        "git://github.com/#{$1}.git"
      when /^https?:\/\/github.com\/(.+)/
        "git://github.com/#{$1}"
      when /^git@github.com:(.+)\.git$/
        "git://github.com/#{$1}.git"
      else
        @url
      end
    end

		def validate_server_connection
			return unless valid?
			@errors << [:failed, "The server did not respond to the 'git-ls-remote' command. Is the URL correct?"] unless self.exists?
		end

		def guess_forge
			u = @url =~ /:\/\/(.*\.?git\.)?([^\/^:]+)(:\d+)?\// ? $2 : nil
			case u
			when /(sourceforge\.net$)/
				$1
			else
				u
			end
		end
	end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
ohloh_scm-2.5.1 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.14 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.13 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.12 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.11 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.10 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.9 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.8 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.7 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.6 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.5 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.4 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.3 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.1 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.4.0 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.3.5 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.3.4 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.3.2 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.3.1 lib/ohloh_scm/adapters/git/validation.rb
ohloh_scm-2.3.0 lib/ohloh_scm/adapters/git/validation.rb