Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created May 14, 2013 08:18
Show Gist options
  • Save kyanny/5574460 to your computer and use it in GitHub Desktop.
Save kyanny/5574460 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'octokit'
def usage
puts <<USAGE
Usage: #{File.basename($0)} [user/repo] ref
#{File.basename($0)} defunkt/hub master
#{File.basename($0)} feature # branch name only
USAGE
end
def detect_user_repo
`git config --get remote.origin.url`.chomp.match(/github\.com[:\/](\w+)\/(\w+)\.git$/)[1,2]
end
case ARGV.length
when 2
user, repo = ARGV[0].split('/')
branch = ARGV[1]
when 1
user, repo = detect_user_repo
branch = ARGV[0]
else
usage
exit!
end
if user.nil? || repo.nil? || branch.nil?
usage
exit!
end
oauth_token = ENV['OAUTH_TOKEN']
unless oauth_token
puts "OAUTH_TOKEN is required"
puts ""
usage
exit!
end
client = Octokit::Client.new(oauth_token: oauth_token)
hooks = client.hooks("#{user}/#{repo}")
hook = hooks.detect{ |hook| hook.name == 'travis' }
refs = client.refs("#{user}/#{repo}", "heads/#{branch}")
sha = refs.object.sha
p hook.test_url
p sha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment