Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Created January 10, 2014 17:57
Show Gist options
  • Save davidcornu/8359220 to your computer and use it in GitHub Desktop.
Save davidcornu/8359220 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
token = ENV['CIRCLE_CI_TOKEN']
repo_match = `git config --get remote.origin.url`.chomp.match(/git@github.com:(.+)\.git/)
if repo_match.nil?
warn "Current directory is not a git repository"
exit(1)
end
repo = repo_match[1]
builds = JSON.parse(open("https://circleci.com/api/v1/project/#{repo}/tree/master?circle-token=#{token}").read)
unless green = builds.select { |b| b['outcome'] == 'success' }.sort_by { |b| b['build_num'] }.last
warn "Could not find green test run on master"
exit(1)
end
puts green['vcs_revision']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment