module GitBak::Services::GitHub

Constants

API
HEADERS
HTTPS
SSH

Public Class Methods

configure(cfg, dir, opts = {}) click to toggle source
# File lib/gitbak/services/github.rb, line 30
def self.configure(cfg, dir, opts = {})                     # {{{1
  u = opts[:user] or raise 'no user'                        # TODO
  c = cfg[:github] ||= []
  a = if opts[:auth] == false
    nil
  elsif opts[:token]
    t = GitBak::Misc.prompt "token for github/#{u}: ", true
    { user: t, pass: '' }
  else
    p = GitBak::Misc.prompt "password for github/#{u}: ", true
    { user: u, pass: p }
  end
  c << { dir: dir, user: u, auth: a, method: opts[:method] }
end
fetch(cfg, verbose) click to toggle source
# File lib/gitbak/services/github.rb, line 45
def self.fetch(cfg, verbose)                                # {{{1
  pag = method :next_page; join = GitBak.method :cat_json
  (cfg[:github] || []).each do |x|
    meth = x[:method] == :https ? HTTPS : SSH
    info = "github/#{x[:user]}"
    print "fetching #{info} ..." if verbose
    repos = GitBak.paginate API, HEADERS, info, x[:auth], nil,
      pag, join
    x[:repos] = repos.map do |r|
      { name: r['name'], remote: meth[x[:user], r['name']],
        description: r['description'] }
    end
    puts " #{repos.length} repositories" if verbose
  end
end
mirror(cfg, verbose, noact) click to toggle source
# File lib/gitbak/services/github.rb, line 61
def self.mirror(cfg, verbose, noact)                        # {{{1
  (cfg[:github] || []).each do |x|
    x[:repos].each do |r|
      GitBak.show_mirror 'github', x[:user], r[:name], r[:description]
      GitBak.mirror_repo verbose, noact, r[:remote], x[:dir]
      puts if verbose
    end
  end
end
next_page(data) click to toggle source
# File lib/gitbak/services/github.rb, line 24
def self.next_page(data)
  (l = data.meta['link']) &&
  (n = l.split(',').grep(/rel="next"/).first) &&
  (r = l.match(%r{<(https://[^>]*)>})) && r[1]
end
summarise(cfg) click to toggle source
# File lib/gitbak/services/github.rb, line 71
def self.summarise(cfg)
  (cfg[:github] || []).each do |x|
    GitBak.show_summary "github/#{x[:user]}", x[:repos].length
  end
end