Class: Boxen::Hook::GitHubIssue

Inherits:
Boxen::Hook show all
Defined in:
lib/boxen/hook/github_issue.rb

Instance Attribute Summary collapse

Attributes inherited from Boxen::Hook

#checkout, #config, #puppet, #result

Instance Method Summary collapse

Methods inherited from Boxen::Hook

all, #enabled?, #initialize, register, #run, unregister

Constructor Details

This class inherits a constructor from Boxen::Hook

Instance Attribute Details

#failure_labelObject



95
96
97
# File 'lib/boxen/hook/github_issue.rb', line 95

def failure_label
  @failure_label ||= 'failure'
end

#ongoing_labelObject



100
101
102
# File 'lib/boxen/hook/github_issue.rb', line 100

def ongoing_label
  @ongoing_label ||= 'ongoing'
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
# File 'lib/boxen/hook/github_issue.rb', line 13

def call
  if result.success?
    close_failures
  else
    warn "Sorry! Creating an issue on #{config.reponame}."
    record_failure
  end
end

#close_failuresObject



51
52
53
54
55
56
57
58
59
# File 'lib/boxen/hook/github_issue.rb', line 51

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



22
23
24
25
# File 'lib/boxen/hook/github_issue.rb', line 22

def compare_url
  return unless config.reponame
  "#{config.ghurl}/#{config.reponame}/compare/#{checkout.sha}...master"
end

#failure_detailsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/boxen/hook/github_issue.rb', line 70

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



61
62
63
64
65
66
67
68
# File 'lib/boxen/hook/github_issue.rb', line 61

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



27
28
29
# File 'lib/boxen/hook/github_issue.rb', line 27

def hostname
  `hostname`.strip
end

#issues?Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
# File 'lib/boxen/hook/github_issue.rb', line 105

def issues?
  return unless config.reponame
  return if config.reponame == 'boxen/our-boxen'

  config.api.repository(config.reponame).has_issues
end

#logObject



39
40
41
# File 'lib/boxen/hook/github_issue.rb', line 39

def log
  File.read config.logfile
end

#osObject



31
32
33
# File 'lib/boxen/hook/github_issue.rb', line 31

def os
  `sw_vers -productVersion`.strip
end

#perform?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'lib/boxen/hook/github_issue.rb', line 6

def perform?
  enabled? &&
  !config.stealth? && !config.pretend? &&
  !config..to_s.empty? &&
  checkout.master?
end

#record_failureObject



43
44
45
46
47
48
49
# File 'lib/boxen/hook/github_issue.rb', line 43

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



35
36
37
# File 'lib/boxen/hook/github_issue.rb', line 35

def shell
  ENV["SHELL"]
end