Skip to content

Instantly share code, notes, and snippets.

@mislav
Forked from gorenje/feature_branch.rb
Created May 6, 2012 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mislav/2623564 to your computer and use it in GitHub Desktop.
Save mislav/2623564 to your computer and use it in GitHub Desktop.
hub extension command

Save the script as an executable named something like git-github-issues. Then you can invoke it as git github-issues.

The script it standalone. hub not needed.

#!/usr/bin/env ruby -w
require 'net/https'
require 'json'
unless `git config --get-all remote.origin.url` =~ %r{\bgithub\.com[:/]([^/\s]+)/([^/\s]+)}
abort "no GitHub URL found in origin remote"
end
owner = $1
repo = $2.sub(/\.git$/, '')
closed = ARGV.include? '-c'
uri = URI "https://api.github.com/repos/#{owner}/#{repo}/issues"
uri.query = 'state=closed' if closed
http = Net::HTTP.new uri.host, uri.port
http.use_ssl = true
response = http.start { http.get uri.request_uri }
unless Net::HTTPSuccess === response
abort "GitHub API fetch failed with status #{response.code}"
end
data = JSON.parse response.body
begin
data.each do |issue|
puts '%3d. %s' % [ issue['number'], issue['title'] ]
end
rescue Errno::EPIPE
# ignore broken pipe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment