Created
January 10, 2014 17:57
-
-
Save davidcornu/8359220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
require 'open-uri' | |
token = ENV['CIRCLE_CI_TOKEN'] | |
repo_match = `git config --get remote.origin.url`.chomp.match(/[email protected]:(.+)\.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