Class: OpsWalrus::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/opswalrus/git.rb

Class Method Summary collapse

Class Method Details

.repo?(repo_reference) ⇒ Boolean

repo?(“davidkellis/arborist”) -> “github.com/davidkellis/arborist” returns the repo URL or directory path

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/opswalrus/git.rb', line 7

def self.repo?(repo_reference)
  if Dir.exist?(repo_reference)
    ::Git.ls_remote(repo_reference) && repo_reference rescue nil
  else
    candidate_repo_references = [
      repo_reference,
      repo_reference =~ /(\.(com|net|org|dev|io|local))\// && "https://#{repo_reference}",
      repo_reference !~ /github\.com\// && repo_reference =~ /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}\/([\w\.@\:\-~]+)$/i && "https://github.com/#{repo_reference}"    # this regex is from https://www.npmjs.com/package/github-username-regex and https://www.debuggex.com/r/H4kRw1G0YPyBFjfm
    ].compact
    working_repo_reference = candidate_repo_references.find {|reference| ::Git.ls_remote(reference) rescue nil }
    working_repo_reference
  end
end