Class: Denmark
- Inherits:
-
Object
show all
- Defined in:
- lib/denmark.rb,
lib/denmark/version.rb
Defined Under Namespace
Classes: Plugins, Repository
Constant Summary
collapse
- VERSION =
'0.0.1'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.config(*args) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/denmark.rb', line 18
def self.config(*args)
if args.empty?
@config
else
@config.dig(*args)
end
end
|
.config=(arg) ⇒ Object
14
15
16
17
|
# File 'lib/denmark.rb', line 14
def self.config=(arg)
raise "Requires a Hash to set config, not a #{arg.class}" unless arg.is_a? Hash
@config = arg
end
|
.evaluate(slug, options) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/denmark.rb', line 32
def self.evaluate(slug, options)
@options = options
slug.sub!('/', '-')
begin
mod = PuppetForge::Module.find(slug)
rescue Faraday::BadRequestError, Faraday::ResourceNotFound
raise "The module `#{slug}` was not found on the Puppet Forge."
end
repo = Denmark::Repository.new(mod.homepage_url)
data = Denmark::Plugins.new(options).run(mod, repo)
case options[:format]
when 'json'
puts JSON.pretty_generate(data)
when 'human'
generate_report(data)
else
raise 'unknown format'
end
end
|
.generate_report(data) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/denmark.rb', line 54
def self.generate_report(data)
if data.empty?
puts "Congrats, no smells discovered"
else
puts
[:red, :orange, :yellow, :green].each do |severity|
alerts = data.select {|i| i[:severity] == severity}
next unless alerts.size > 0
puts "[#{severity.upcase}] alerts:".colorize(severity)
alerts.each do |alert|
puts " #{alert[:message]}"
puts " > #{alert[:explanation]}" if @options[:detail]
end
puts
end
end
end
|
.info(slug) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/denmark.rb', line 74
def self.info(slug)
mod = PuppetForge::Module.find(slug)
puts mod.owner.username
puts mod.owner.display_name
puts mod.current_release.version
puts mod.current_release.created_at
puts mod.current_release.changelog
puts mod.current_release.reference
puts mod.current_release.license
puts mod.homepage_url
puts mod.current_release.metadata['project_page']
puts mod.current_release.metadata['source']
puts mod.issues_url
client = Octokit::Client.new
repo = Octokit::Repository.from_url(mod.homepage_url, options)
require 'pry'
binding.pry
puts client.pull_requests(repo)
puts client.list_issues(repo)
end
|
.list(options) ⇒ Object
27
28
29
30
|
# File 'lib/denmark.rb', line 27
def self.list(options)
puts
puts Denmark::Plugins.new(options).list
end
|
Instance Method Details
#github_client ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/denmark.rb', line 100
def github_client
@token ||= ENV['GITHUB_TOKEN'] || `git config --global github.token`.chomp
if @token.empty?
puts "You need to generate a GitHub token:"
puts "\t * https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line"
puts "\t * git config --global github.token <token>"
puts
puts "Export that as the `GITHUB_TOKEN` environment variable or put it in your ~/.gitconfig."
exit 1
end
begin
client = Octokit::Client.new(:access_token => @token)
rescue => e
puts "Github login error: #{e.message}"
exit 1
end
client
end
|