Class: Boxen::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/boxen/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checkoutObject (readonly)

Returns the value of attribute checkout.



4
5
6
# File 'lib/boxen/reporter.rb', line 4

def checkout
  @checkout
end

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/boxen/reporter.rb', line 3

def config
  @config
end

#failure_labelObject



86
87
88
# File 'lib/boxen/reporter.rb', line 86

def failure_label
  @failure_label ||= 'failure'
end

#ongoing_labelObject



91
92
93
# File 'lib/boxen/reporter.rb', line 91

def ongoing_label
  @ongoing_label ||= 'ongoing'
end

#puppetObject (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_failuresObject



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_urlObject



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_detailsObject



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

#failuresObject



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.)
  issues.reject! {|i| i.labels.collect(&:name).include?(ongoing_label)}
  issues
end

#hostnameObject



18
19
20
# File 'lib/boxen/reporter.rb', line 18

def hostname
  `hostname`.strip
end

#issues?Boolean

Returns:

  • (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

#logObject



30
31
32
# File 'lib/boxen/reporter.rb', line 30

def log
  File.read config.logfile
end

#osObject



22
23
24
# File 'lib/boxen/reporter.rb', line 22

def os
  `sw_vers -productVersion`.strip
end

#record_failureObject



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

#shellObject



26
27
28
# File 'lib/boxen/reporter.rb', line 26

def shell
  ENV["SHELL"]
end