Class: Github

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

Constant Summary collapse

TOKEN =
ENV['github_token']
SERVER =
"https://api.github.com"
HOME =
ENV['HOME']

Class Method Summary collapse

Class Method Details

.clone(web, group_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/github.rb', line 18

def self.clone(web, group_name)
  repos_list = get_repos(group_name)
  repos_dir = "#{HOME}/projects/#{group_name}"

  if File.directory?("#{repos_dir}")
    FileUtils::mkdir_p repos_dir
  end

  if web == 1
    repo_location = 'clone_url'
    message = "Web"
  else
    repo_location = 'ssh_url'
    message = "Ssh"
  end
  puts "-------------------------------------------------------------------\n"
  puts "\t### Starting #{message} Clone Process Of The Org #{group_name} ###\n\n"
  puts "\tDownloading #{repos_list.count} repo(s) into #{repos_dir}\n\n"

  repos_list.each do |get|
    repo_name = get["name"]
    repo = get["#{repo_location}"]
    dir = get["name"]
    repo_dir = "#{repos_dir}/#{dir}"

    if File.directory?("#{repo_dir}")
      puts "\t#{repo_name} directory exists, doing a git pull instead."
      Dir.chdir("#{repo_dir}")
      g = Git.init
      g.pull
    else
      puts "\tCloning #{repo_name}..."
      Git.clone("#{repo}", "#{repo_dir}")
    end
  end
  puts "-------------------------------------------------------------------\n"
end

.get_repos(group_name) ⇒ Object



56
57
58
59
# File 'lib/github.rb', line 56

def self.get_repos(group_name)
  string = HTTParty.get("#{SERVER}/orgs/#{group_name}/repos", :headers => {"Authorization" => "token #{TOKEN}", 'User-Agent' => 'HTTParty'},  :verify => false).to_json
  rep = JSON.parse(string)
end

.list_repos(group_name) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/github.rb', line 7

def self.list_repos(group_name)
  repos_list = get_repos(group_name)
  puts "-------------------------------------------------------------------\n"
  puts "\tThe following #{repos_list.count} repo(s) were found in the Org #{group_name}.\n\n"
  repos_list.each do |get|
    puts "\t\t#{get["name"]}"
  end
  puts "\n-------------------------------------------------------------------"
end