-
-
Save rue/364349 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 "rubygems" | |
require "mutter" | |
require "httparty" | |
REMOTE = "origin" | |
REPO = `git config --get remote.#{REMOTE}.url`.chomp[/github\.com[\/\:]([^\/]+\/[^\/]+)\.git/, 1] | |
USER = `git config --get github.user`.chomp | |
TOKEN = `git config --get github.token`.chomp | |
class Issue | |
include HTTParty | |
base_uri "https://github.com/api/v2/json/issues" | |
default_params :login => USER, :token => TOKEN, :output => 'json' | |
format :json | |
def self.open(title) | |
id = post("/open/#{REPO}", :query => { :title => title })["issue"]["number"] | |
puts "Issue #{id} created." | |
end | |
def self.close(*ids) | |
ids.each do |id| | |
post("/close/#{REPO}/#{id}") | |
puts "Issue #{id} closed." | |
end | |
end | |
def self.view(id) | |
system "open https://github.com/#{REPO}/issues/#issue/#{id}" | |
end | |
def self.browse | |
system "open https://github.com/#{REPO}/issues" | |
end | |
def self.list(status="open") | |
table = Mutter::Table.new do | |
column :width => 3, :style => [:bold, :green], :align => :right | |
column :style => :yellow | |
column | |
end | |
get("/list/#{REPO}/#{status}")["issues"].each { |issue| table << issue.values_at("number", "user", "title") } | |
puts table.to_s | |
end | |
end | |
case cmd = ARGV.shift | |
when /^\d+$/ | |
Issue.view cmd | |
when nil, "list" | |
Issue.list | |
when "close", "c" | |
Issue.close *ARGV | |
when "browse", "b" | |
Issue.browse | |
when "help", "-h", "--help" | |
abort <<-EOS | |
GitHub Issues power script | |
usage: | |
List issues: ghi | |
Create an issue: ghi "Your project sucks" | |
View an issue: ghi 7 | |
Close an issue: ghi close 7 or ghi c 7 or ghi c 7 8 9 | |
Open browser: ghi browse or ghi b | |
EOS | |
else | |
Issue.open cmd | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment