Class: Boxen::Reporter
- Inherits:
-
Object
- Object
- Boxen::Reporter
- Defined in:
- lib/boxen/reporter.rb
Instance Attribute Summary collapse
-
#checkout ⇒ Object
readonly
Returns the value of attribute checkout.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
- #failure_label ⇒ Object
- #ongoing_label ⇒ Object
-
#puppet ⇒ Object
readonly
Returns the value of attribute puppet.
Instance Method Summary collapse
- #close_failures ⇒ Object
- #compare_url ⇒ Object
- #failure_details ⇒ Object
- #failures ⇒ Object
- #hostname ⇒ Object
-
#initialize(config, checkout, puppet) ⇒ Reporter
constructor
A new instance of Reporter.
- #issues? ⇒ Boolean
- #log ⇒ Object
- #os ⇒ Object
- #record_failure ⇒ Object
- #shell ⇒ Object
Constructor Details
#initialize(config, checkout, puppet) ⇒ Reporter
Returns a new instance of Reporter.
7 8 9 10 11 |
# File 'lib/boxen/reporter.rb', line 7 def initialize(config, checkout, puppet) @config = config @checkout = checkout @puppet = puppet end |
Instance Attribute Details
#checkout ⇒ Object (readonly)
Returns the value of attribute checkout.
4 5 6 |
# File 'lib/boxen/reporter.rb', line 4 def checkout @checkout end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/boxen/reporter.rb', line 3 def config @config end |
#failure_label ⇒ Object
86 87 88 |
# File 'lib/boxen/reporter.rb', line 86 def failure_label @failure_label ||= 'failure' end |
#ongoing_label ⇒ Object
91 92 93 |
# File 'lib/boxen/reporter.rb', line 91 def ongoing_label @ongoing_label ||= 'ongoing' end |
#puppet ⇒ Object (readonly)
Returns the value of attribute puppet.
5 6 7 |
# File 'lib/boxen/reporter.rb', line 5 def puppet @puppet end |
Instance Method Details
#close_failures ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/boxen/reporter.rb', line 42 def close_failures return unless issues? comment = "Succeeded at version #{checkout.sha}." failures.each do |issue| config.api.add_comment(config.reponame, issue.number, comment) config.api.close_issue(config.reponame, issue.number) end end |
#compare_url ⇒ Object
13 14 15 16 |
# File 'lib/boxen/reporter.rb', line 13 def compare_url return unless config.reponame "https://github.com/#{config.reponame}/compare/#{checkout.sha}...master" end |
#failure_details ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/boxen/reporter.rb', line 61 def failure_details body = '' body << "Running on `#{hostname}` (OS X #{os}) under `#{shell}`, " body << "version #{checkout.sha} ([compare to master](#{compare_url}))." body << "\n\n" if checkout.dirty? body << "### Changes" body << "\n\n" body << "```\n#{checkout.changes}\n```" body << "\n\n" end body << "### Puppet Command" body << "\n\n" body << "```\n#{puppet.command.join(' ')}\n```" body << "\n\n" body << "### Output (from #{config.logfile})" body << "\n\n" body << "```\n#{log}\n```\n" body end |
#failures ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/boxen/reporter.rb', line 52 def failures return [] unless issues? issues = config.api.list_issues(config.reponame, :state => 'open', :labels => failure_label, :creator => config.login) issues.reject! {|i| i.labels.collect(&:name).include?(ongoing_label)} issues end |
#hostname ⇒ Object
18 19 20 |
# File 'lib/boxen/reporter.rb', line 18 def hostname `hostname`.strip end |
#issues? ⇒ Boolean
96 97 98 99 100 101 |
# File 'lib/boxen/reporter.rb', line 96 def issues? return unless config.reponame return if config.reponame == 'boxen/our-boxen' config.api.repository(config.reponame).has_issues end |
#log ⇒ Object
30 31 32 |
# File 'lib/boxen/reporter.rb', line 30 def log File.read config.logfile end |
#os ⇒ Object
22 23 24 |
# File 'lib/boxen/reporter.rb', line 22 def os `sw_vers -productVersion`.strip end |
#record_failure ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/boxen/reporter.rb', line 34 def record_failure return unless issues? title = "Failed for #{config.user}" config.api.create_issue(config.reponame, title, failure_details, :labels => [failure_label]) end |
#shell ⇒ Object
26 27 28 |
# File 'lib/boxen/reporter.rb', line 26 def shell ENV["SHELL"] end |