Module: RepoDependencyGraph

Defined in:
lib/repo_dependency_graph.rb,
lib/repo_dependency_graph/cli.rb,
lib/repo_dependency_graph/output.rb,
lib/repo_dependency_graph/version.rb

Defined Under Namespace

Modules: CLI, Output

Constant Summary collapse

VERSION =
"0.6.0"

Class Method Summary collapse

Class Method Details

.dependencies(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/repo_dependency_graph.rb', line 9

def dependencies(options)
  if options[:map] && options[:external]
    raise ArgumentError, "Map only makes sense when searching for internal repos"
  end

  all = OrganizationAudit::Repo.all(options.slice(:user, :organization, :token, :max_pages)).sort_by(&:name)
  all.select!(&:private?) if options[:private]
  all.select! { |r| r.name =~ options[:select] } if options[:select]
  all.reject! { |r| r.name =~ options[:reject] } if options[:reject]

  possible = all.map(&:name)
  possible.map! { |p| p.sub(options[:map][0], options[:map][1].to_s) } if options[:map]

  dependencies = all.map do |repo|
    found = dependent_repos(repo, options)
    found.select! { |f| possible.include?(f.first) } unless options[:external]
    next if found.empty?
    puts "#{repo.name}: #{found.map { |n,v| "#{n}: #{v}" }.join(", ")}"
    [repo.name, found]
  end.compact
  Hash[dependencies]
end