Module: Github

Included in:
Cloner
Defined in:
lib/github_cloner/github_helper.rb

Constant Summary collapse

GITHUB_URL_API =
'http://github.com/api/v2/json/repos/show/'

Class Method Summary collapse

Class Method Details

.get_repos(username, mode, timeout) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/github_cloner/github_helper.rb', line 11

def get_repos(username, mode, timeout)
  repos_json = JSON.parse(open(GITHUB_URL_API+username).read)
  repos = []
  repos_json['repositories'].each do |repo| 
    if timeout != "" && inactive?(repo, timeout) 
      repos << make_git_url(repo['name'], mode, username, "_inactive") 
    else
      repos << make_git_url(repo['name'], mode, username, "") 
    end
  end
  repos	
end

.git_config_nameObject



39
40
41
# File 'lib/github_cloner/github_helper.rb', line 39

def git_config_name
  `git config --global --get github.user`
end

.inactive?(repo, timeout) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/github_cloner/github_helper.rb', line 35

def inactive?(repo, timeout)
  ((Time.now - Time.parse(repo["pushed_at"])).to_i / 86400) > timeout.to_i
end

.make_git_url(repo_name, mode, username, inactive) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/github_cloner/github_helper.rb', line 24

def make_git_url(repo_name, mode, username, inactive)
  case mode
    when 'ssh'
      {:link => "[email protected]:#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
    when 'http'
      {:link => "https://#{username}@github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
    when 'git'
      {:link => "git://github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
  end
end