Skip to content

Instantly share code, notes, and snippets.

@mhl
Created January 4, 2013 21:37
Show Gist options
  • Save mhl/4456740 to your computer and use it in GitHub Desktop.
Save mhl/4456740 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -w
require 'json'
require 'net/https'
require 'pp'
usage_message = <<EOUSAGE
Usage: #{$0} <OWNER> <RESPOSITORY-NAME> <REF>
For example, you could run:
#{$0} acardona CATMAID refs/heads/master
EOUSAGE
unless ARGV.length == 3
STDERR.puts usage_message
exit(1)
end
owner, repository_name, ref = ARGV
# You can generate a token using cURL, as described here:
# https://help.github.com/articles/creating-an-oauth-token-for-command-line-use
token = nil
open(ENV['HOME']+ '/.github-oauth-token.json') do |f|
token = JSON.parse(f.read)['token']
end
unless token
STDERR.puts "Failed to find the GitHub API token"
exit(1)
end
# Now fetch the list of repositories from the GitHub API:
http = Net::HTTP.new('api.github.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_path = '/etc/ssl/certs'
response = http.get("/repos/#{owner}/#{repository_name}/events",
'Authorization' => "bearer #{token}")
if response.code != '200'
STDERR.puts "The GitHub API call failed with status #{response.code}: #{response.body}"
exit(1)
end
push_events = JSON.parse(response.body).select { |x|
x['type'] == 'PushEvent' && x['payload']['ref'] == ref
}
pp push_events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment