Last active
December 14, 2015 17:17
-
-
Save tomstuart/35ede17f981a7fb80c7c to your computer and use it in GitHub Desktop.
Revisions
-
tomstuart revised this gist
Dec 14, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ TRIES.times do |n| projects. flat_map { |project| project['builds'] }. select { |build| build['commit_id'] == current_sha }. max_by { |build| Time.iso8601(build['started_at'] || Time.now) } break if build -
tomstuart revised this gist
Nov 25, 2015 . 1 changed file with 18 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ require 'time' API_ENDPOINT = 'https://codeship.com/api/v1/projects.json' API_KEY = ENV['CODESHIP_API_KEY'] || raise('set CODESHIP_API_KEY first! get it from https://codeship.com/user/edit#user_api_key') TRIES = 5 WAIT_BETWEEN_TRIES = 2 current_sha = `git rev-parse HEAD`.chomp raise 'git failed — not a git repo?' unless $?.success? @@ -15,12 +17,22 @@ projects_uri = URI.parse(API_ENDPOINT).tap do |uri| uri.query = URI.encode_www_form(api_key: API_KEY) end build = nil TRIES.times do |n| puts "not on Codeship yet, retrying (#{n.succ} of #{TRIES})…" unless n.zero? projects = JSON.parse(Net::HTTP.get(projects_uri))['projects'] build = projects. flat_map { |project| project['builds'] }. select { |build| build['commit_id'] == current_sha }. max_by { |build| Time.iso8601(build['started_at']) } break if build sleep WAIT_BETWEEN_TRIES end raise "no Codeship build matching #{current_sha}" unless build -
tomstuart created this gist
Nov 25, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/usr/bin/env ruby require 'json' require 'net/https' require 'time' API_ENDPOINT = 'https://codeship.com/api/v1/projects.json' API_KEY = ENV['CODESHIP_API_KEY'] || raise('set CODESHIP_API_KEY first! get it from https://codeship.com/user/edit#user_api_key') current_sha = `git rev-parse HEAD`.chomp raise 'git failed — not a git repo?' unless $?.success? projects_uri = URI.parse(API_ENDPOINT).tap do |uri| uri.query = URI.encode_www_form(api_key: API_KEY) end projects = JSON.parse(Net::HTTP.get(projects_uri))['projects'] build = projects. flat_map { |project| project['builds'] }. select { |build| build['commit_id'] == current_sha }. max_by { |build| Time.iso8601(build['started_at']) } raise "no Codeship build matching #{current_sha}" unless build project_id, build_id = build.values_at('project_id', 'id').map(&:to_s).map(&URI.method(:escape)) build_uri = "https://codeship.com/projects/#{project_id}/builds/#{build_id}" puts "opening #{build_uri}…" exec 'open', build_uri