class Boxen::Hook::GitHubIssue

Attributes

failure_label[W]
ongoing_label[W]

Public Instance Methods

call() click to toggle source
# 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_failures() click to toggle source
# 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_url() click to toggle source
# 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_details() click to toggle source
# 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
failure_label() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 95
def failure_label
  @failure_label ||= 'failure'
end
failures() click to toggle source
# 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.login)
  issues.reject! {|i| i.labels.collect(&:name).include?(ongoing_label)}
  issues
end
hostname() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 27
def hostname
  `hostname`.strip
end
issues?() click to toggle source
# 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
log() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 39
def log
  File.read config.logfile
end
ongoing_label() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 100
def ongoing_label
  @ongoing_label ||= 'ongoing'
end
os() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 31
def os
  `sw_vers -productVersion`.strip
end
perform?() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 6
def perform?
  enabled? &&
  !config.stealth? && !config.pretend? &&
  !config.login.to_s.empty? &&
  checkout.master?
end
record_failure() click to toggle source
# 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
shell() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 35
def shell
  ENV["SHELL"]
end

Private Instance Methods

required_environment_variables() click to toggle source
# File lib/boxen/hook/github_issue.rb, line 113
def required_environment_variables
  ['BOXEN_ISSUES_ENABLED']
end