Skip to content

Instantly share code, notes, and snippets.

@bernardeli
Last active February 23, 2017 03:09
Show Gist options
  • Save bernardeli/30b4c4da853250f16376c07e78058105 to your computer and use it in GitHub Desktop.
Save bernardeli/30b4c4da853250f16376c07e78058105 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'httparty'
def notify(title: "Buildkite", message:, icon:, web_url:)
command = "terminal-notifier -title '#{title}' -message '#{message}' -appIcon ~/.buildkite/#{icon}.png"
command += " -open '#{web_url}'" if web_url
`#{command}`
end
token = ENV.fetch("BUILDKITE_TOKEN")
pipeline, build_number = ARGV[0..1]
url = "https://api.buildkite.com/v2/organizations/everyday-hero/pipelines/#{pipeline}/builds/#{build_number}"
state = "unknown"
until ["passed", "failed", "blocked"].include?(state)
resp = HTTParty.get(url, headers: { "Authorization" => "Bearer #{token}" })
if resp.code != 200
notify(
message: "Received a #{resp.code} response from Buildkite. Check your arguments are correct.",
icon: "failed",
)
exit(1)
end
web_url = resp["web_url"]
state = resp["state"]
sleep(5)
end
case state
when "passed"
notify(
title: "Buildkite: #{pipeline}",
message: "##{build_number} passed",
icon: "passed",
web_url: web_url,
)
when "failed"
notify(
title: "Buildkite: #{pipeline}",
message: "##{build_number} passed",
icon: "failed",
web_url: web_url,
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment