class ASF::Git

Provide access to files stored in Git, generally to local clones that are updated via cronjobs.

Constants

GITHUB_HOST

host which can be used to get raw content from git repositories hosted at GitHub.

INFRA_PUPPET

path to the deployment branch on GitHub.

REPOSITORY

path to repository.yml in the source.

Public Class Methods

[](name) click to toggle source

Find a local git clone. Raises an exception if not found.

# File lib/whimsy/asf/git.rb, line 67
def self.[](name)
  self.find!(name)
end
find(name) click to toggle source

Find a local git clone. Returns nil if not found.

# File lib/whimsy/asf/git.rb, line 74
def self.find(name)
  repos[name]
end
find!(name) click to toggle source

Find a local git clone. Raises an exception if not found.

# File lib/whimsy/asf/git.rb, line 81
def self.find!(name)
  result = self.find(name)

  if not result
    raise Exception.new("Unable to find git clone for #{name}")
  end

  result
end
infra_puppet(file) click to toggle source

get a file live from infrastructure puppet (e.g. 'data/common.yaml') issues a HTTP GET request, so may be slow and may fail. For applications that require faster and more dependable access, ASF::Git.find('infrastructure-puppet') may be used to get access to a clone that is updated every 10 minutes.

# File lib/whimsy/asf/git.rb, line 24
def self.infra_puppet(file)
  file = INFRA_PUPPET + file
  http = Net::HTTP.new(GITHUB_HOST, 443)
  http.use_ssl = true
  http.request(Net::HTTP::Get.new(file)).body
end
repos() click to toggle source

Scan a list of git directories, looking for local clones.

# File lib/whimsy/asf/git.rb, line 41
def self.repos
  @semaphore.synchronize do
    git = Array(ASF::Config.get(:git)).map {|dir| dir.untaint}

    unless @repos
      @@repository_mtime = File.exist?(REPOSITORY) && File.mtime(REPOSITORY)

      @repos = Hash[Dir[*git].map { |name|
        next unless Dir.exist? name.untaint
        Dir.chdir name.untaint do
          out, err, status =
            Open3.capture3(*%Q(git config --get remote.origin.url))
          if status.success?
            [File.basename(out.chomp, '.git'), Dir.pwd.untaint]
          end
        end
      }.compact]
    end

    @repos
  end
end