class Twigg::Command::GitHub

The “github” subcommand can be used to conveniently initialize a set of repos and keep them up-to-date.

Constants

API_HOST
API_PORT
ORG_REPOS_ENDPOINT

Private Instance Methods

address(project) click to toggle source
# File lib/twigg/command/git_hub.rb, line 12
def address(project)
  "git@github.com:#{Config.github.organization}/#{project}.git"
end
projects() click to toggle source

Returns the list of all projects hosted within a GitHub organization.

# File lib/twigg/command/git_hub.rb, line 21
def projects
  @projects ||= begin
    http             = Net::HTTP.new(API_HOST, API_PORT)
    http.use_ssl     = true
    http.ca_file     = (Twigg.root + 'files' + 'github.pem').to_s
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    uri              = ORG_REPOS_ENDPOINT % Config.github.organization
    headers          = { 'Authorization' => "token #{Config.github.token}" }

    [].tap do |names|
      begin # loop: page through project list
        request  = Net::HTTP::Get.new(uri, headers)
        response = http.request(request)
        raise "Bad response #{response.inspect}" unless response.is_a?(Net::HTTPOK)
        names.concat JSON[response.body].map { |repo| repo['name'] }
        uri = parse_link(response['Link'])
      end until uri.nil?
    end
  end
end