Module: Gitrob::CLI::Commands::Analyze::Gathering

Included in:
Gitrob::CLI::Commands::Analyze
Defined in:
lib/gitrob/cli/commands/analyze/gathering.rb

Instance Method Summary collapse

Instance Method Details

#client_manager_configurationObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 47

def client_manager_configuration
  {
    :endpoint      => @options[:endpoint],
    :site          => @options[:site],
    :ssl           => {
      :verify => @options[:verify_ssl]
    },
    :access_tokens => github_access_tokens
  }
end

#gather_ownersObject



6
7
8
9
10
11
12
13
14
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 6

def gather_owners
  task("Gathering targets...") do
    thread_pool do |pool|
      github_data_manager.gather_owners(pool)
    end
  end
  fatal("No users or organizations " \
    "found; exiting") if owner_count.zero?
end

#gather_repositoriesObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 16

def gather_repositories
  make_repo_gathering_progress_bar do |progress|
    thread_pool do |pool|
      github_data_manager
        .gather_repositories(pool) do |owner, repositories|
        repository_gathering_update(owner, repositories, progress)
      end
    end
  end
  fatal("No repositories found; exiting") if repo_count.zero?
  info "Gathered #{repo_count} repositories"
end

#github_access_tokensObject



58
59
60
61
62
63
64
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 58

def github_access_tokens
  if @options[:access_tokens]
    @options[:access_tokens].gsub("\n", ",").split(",").map(&:strip)
  else
    Gitrob::CLI.configuration["github_access_tokens"]
  end
end

#github_client_managerObject



38
39
40
41
42
43
44
45
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 38

def github_client_manager
  unless @github_client_manager
    @github_client_manager = Gitrob::Github::ClientManager.new(
      client_manager_configuration
    )
  end
  @github_client_manager
end

#github_data_managerObject



29
30
31
32
33
34
35
36
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 29

def github_data_manager
  unless @github_data_manager
    @github_data_manager = Gitrob::Github::DataManager.new(
      @targets, github_client_manager
    )
  end
  @github_data_manager
end

#make_repo_gathering_progress_barObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 66

def make_repo_gathering_progress_bar
  total = github_data_manager.owners.count
  progress_bar(
    "Gathering repositories from #{total} targets...",
    :total => total
  ) do |progress|
    yield progress
  end
  sleep 0.1
end

#owner_countObject



81
82
83
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 81

def owner_count
  github_data_manager.owners.count
end

#repo_countObject



77
78
79
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 77

def repo_count
  github_data_manager.repositories.count
end

#repository_gathering_update(owner, repositories, progress_bar) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gitrob/cli/commands/analyze/gathering.rb', line 85

def repository_gathering_update(owner, repositories, progress_bar)
  count = repositories.count
  progress_bar.increment
  return if count.zero?
  gathered = Gitrob::Utils.pluralize(
    count,
    "repository",
    "repositories"
  )
  progress_bar.info("Gathered #{gathered} " \
                "from #{owner['login'].bold}")
end