class Status::Github::Statuses

Public Class Methods

new(qa_status, branch, user_sha=nil) click to toggle source
# File lib/status/github/statuses.rb, line 6
def initialize(qa_status, branch, user_sha=nil)
  @qa_status = qa_status
  @branch = branch
  @user_sha = user_sha
  @jenkins = Jenkins.new(branch, sha)
end

Public Instance Methods

request() click to toggle source
# File lib/status/github/statuses.rb, line 13
def request
  Request.new.post(status_api, payload)
end

Private Instance Methods

description() click to toggle source
# File lib/status/github/statuses.rb, line 23
def description
  description_text.tap {|d| puts d}
end
description_text() click to toggle source
# File lib/status/github/statuses.rb, line 27
def description_text
  "Build status: #{@jenkins.state}, QA #{@qa_status}"
end
git_state() click to toggle source
# File lib/status/github/statuses.rb, line 47
def git_state
  states.include?(@jenkins.state) ? states[states.index(@jenkins.state)] : "error"
end
payload() click to toggle source
# File lib/status/github/statuses.rb, line 31
def payload
  {:state => state, :description => description, :target_url => target_url}
end
qa_pass_state?() click to toggle source
# File lib/status/github/statuses.rb, line 61
def qa_pass_state?
  @qa_status == "pass" || @qa_status == "n/a"
end
sha() click to toggle source
# File lib/status/github/statuses.rb, line 55
def sha
  @user_sha || Status.system_call("git log #{@branch} -1 --pretty=format:'%H'")
end
state() click to toggle source

The only states github's API acccepts are “success”, “failure”, “pending”, and “error”.

# File lib/status/github/statuses.rb, line 40
def state
  return "success" if @jenkins.pass? && qa_pass_state?
  return "pending" if @jenkins.pass? && @qa_status != "pass"
  return "pending" if @jenkins.state == "pending"
  git_state
end
states() click to toggle source
# File lib/status/github/statuses.rb, line 51
def states
  %w(error failure)
end
status_api() click to toggle source
# File lib/status/github/statuses.rb, line 19
def status_api
  "/repos/#{Status.owner}/#{Status.repo}/statuses/" + sha + "?access_token=" + Status.token
end
target_url() click to toggle source
# File lib/status/github/statuses.rb, line 35
def target_url
  @jenkins.target_url
end