class Status::Jenkins

Public Class Methods

new(branch, sha=nil) click to toggle source
# File lib/status/jenkins.rb, line 6
def initialize(branch, sha=nil)
  @branch = branch.gsub(/\//, "_")
  @sha = sha
end

Public Instance Methods

pass?() click to toggle source
# File lib/status/jenkins.rb, line 19
def pass?
  status == "success"
end
state() click to toggle source
# File lib/status/jenkins.rb, line 15
def state
  status
end
target_url() click to toggle source
# File lib/status/jenkins.rb, line 11
def target_url
  build_url || "#{Status.ci_url}/job/#{@branch}"
end

Private Instance Methods

any_pending_reasons?() click to toggle source
# File lib/status/jenkins.rb, line 68
def any_pending_reasons?
  response == "not found" || queued? || response["building"] == true
end
build() click to toggle source
# File lib/status/jenkins.rb, line 39
def build
  return last_build["number"] if last_build
  "lastBuild"
end
build_is_in_change_set?(build) click to toggle source
# File lib/status/jenkins.rb, line 93
def build_is_in_change_set?(build)
  return false if build["changeSet"].nil?
  build["changeSet"]["items"].any? do |item|
    item["commitId"] =~ /^#{@sha}/
  end
end
build_url() click to toggle source
# File lib/status/jenkins.rb, line 48
def build_url
  if last_build.nil?
    return
  end
  last_build["url"]
end
ci_response() click to toggle source
# File lib/status/jenkins.rb, line 76
def ci_response
  @ci_response ||= Request.new(:ci).get("/job/#{@branch}/api/json?depth=1")
end
ci_status() click to toggle source
# File lib/status/jenkins.rb, line 33
def ci_status
  return "pending" if any_pending_reasons?
  return "failure" if result_is_failure?
  "success"
end
get_build_for_sha() click to toggle source
# File lib/status/jenkins.rb, line 59
def get_build_for_sha
  return unless @sha
  ci_response["builds"].each do |build|
    return build if last_build_contails_sha?(build)
    return build if build_is_in_change_set?(build)
  end
  nil
end
last_build() click to toggle source
# File lib/status/jenkins.rb, line 55
def last_build
  @last_build ||= get_build_for_sha
end
last_build_contails_sha?(build) click to toggle source
# File lib/status/jenkins.rb, line 88
def last_build_contails_sha?(build)
  return false if build["actions"].nil? || build["actions"][1].nil?
  build["actions"][1]["lastBuiltRevision"]["SHA1"] =~ /^#{@sha}/
end
path() click to toggle source
# File lib/status/jenkins.rb, line 25
def path
  "/job/#{@branch}/#{build}/api/json"
end
queued?() click to toggle source
# File lib/status/jenkins.rb, line 80
def queued?
  (!!ci_response["queueItem"]).tap do |queued|
    if queued
      Status.system_warn "Your build (#{@branch}) is in a queue."
    end
  end
end
response() click to toggle source
# File lib/status/jenkins.rb, line 72
def response
  @response ||= Request.new(:ci).get(path)
end
result_is_failure?() click to toggle source
# File lib/status/jenkins.rb, line 44
def result_is_failure?
  response["result"].downcase != "success"
end
status() click to toggle source
# File lib/status/jenkins.rb, line 29
def status
  @status ||= ci_status
end