41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/chef/knife/github_compare.rb', line 41
def run
validate_base_options
display_debug_info
get_all_repos = get_all_repos(@github_organizations.reverse)
cookbooks = rest.get_rest("/cookbooks?num_version=1")
git_link = get_repo_clone_link
if config[:fields] || config[:fieldlist]
all_repos = get_all_repos
config[:fields] = "name" if config[:fields].nil? || config[:fields].empty?
else
all_repos = {}
if config[:all]
get_all_repos.each { |k,v|
cookbooks[k].nil? || cookbooks[k]['versions'].nil? ? version = "" : version = cookbooks[k]['versions'][0]['version']
all_repos[k] = { 'name' => k, 'latest_cb_tag' => version, 'git_url' => v[git_link], 'latest_gh_tag' => v['latest_tag'] }
}
else
cookbooks.each { |k,v|
get_all_repos[k].nil? || get_all_repos[k][git_link].nil? ? gh_url = ui.color("Cannot find cookbook!", :red) : gh_url = get_all_repos[k][git_link]
get_all_repos[k].nil? || get_all_repos[k]['latest_tag'].nil? || get_all_repos[k]['latest_tag'].empty? ? gh_tag = ui.color("No tags!", :red) : gh_tag = get_all_repos[k]['latest_tag']
all_repos[k] = { 'name' => k, 'latest_cb_tag' => v['versions'][0]['version'], 'git_url' => gh_url, 'latest_gh_tag' => gh_tag }
}
end
end
@cookbook_name = name_args.first unless name_args.empty?
if @cookbook_name
repos = all_repos.select { |k,v| v["name"] == @cookbook_name }
else
repos = all_repos
end
columns = [ 'name,Chef Store', 'latest_cb_tag,Tag', 'git_url,Github Store', 'latest_gh_tag,Tag' ]
match = [ 'latest_cb_tag', 'latest_gh_tag' ]
if repos.nil? || repos.empty?
Chef::Log.error("No repositories found.")
else
display_info(repos, columns, match)
end
end
|