Class: Baya::Adapters::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/baya/adapters/github.rb

Constant Summary collapse

API_ROOT =
"https://api.github.com/"

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Github

Returns a new instance of Github.



11
12
13
14
# File 'lib/baya/adapters/github.rb', line 11

def initialize(config)
  @config = config
  check_config
end

Instance Method Details

#archive(root) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/baya/adapters/github.rb', line 16

def archive(root)
  repos.each do |url|
    name = url.split('/').last.gsub(/\.git$/, "")
    git = Git.new('origin' => url, 'destination' => name)
    git.archive(root + '/' + @config['destination'])
  end
end

#reposObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/baya/adapters/github.rb', line 24

def repos
  api_url = API_ROOT + target
  http = Curl.get(api_url) do |http|
    http.useragent = "baya"
  end
  json = http.body_str
  data = Yajl::Parser.parse(json)

  unless http.response_code == 200
    if data["message"]
      raise "Github remote error: #{data["message"]}"
    end
    raise "Unknown remote error from Github"
  end

  data.map do |repo|
    repo['clone_url']
  end
end