Skip to content

Instantly share code, notes, and snippets.

@macournoyer
Created October 29, 2008 15:26
Show Gist options
  • Save macournoyer/20719 to your computer and use it in GitHub Desktop.
Save macournoyer/20719 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Lil' script to fix or implement Fogbugz tickets from the command line.
# Usage:
# Edit `base_uri`.
# fogbugz login email@example.com password
# Copy the returned token and paste on the `default_params` line.
# fogbugz fix 1234 "I IZ TEH AWESOME"
require "rubygems"
require "httparty"
class Fogbugz
include HTTParty
base_uri "http://yourfogbugz.com/"
# Get your token by first running the login command
# default_params :token => "xxxxxxxxxxxxxxxxxx"
def fix(bugzid, message)
resolve(2, bugzid, message)
end
def impl(bugzid, message)
resolve(8, bugzid, message)
end
def resolve(status, bugzid, message)
get(:cmd => "resolve", "ixBug" => bugzid, "ixStatus" => status, "sEvent" => message)
end
def login(email, password)
res = get(:cmd => "logon", :email => email, :password => password)
res["response"]["token"]
end
private
def get(query)
res = self.class.get("/api.asp", :query => query)
if error = res["response"]["error"]
raise error
else
res
end
end
end
def usage(cmd, required, args)
abort "usage: #{$0} #{cmd} #{args.join(' ')}" if ARGV.size < 1 + required
end
fogbugz = Fogbugz.new
case ARGV.first
when "login"
usage :login, 2, %w(email password)
puts fogbugz.login(ARGV[1], ARGV[2])
when "fix"
usage :fix, 1, %w(bugzid message)
fogbugz.fix(ARGV[1], ARGV[2])
puts "#{ARGV[1]} fixed"
when "impl"
usage :fix, 1, %w(bugzid message)
fogbugz.impl(ARGV[1], ARGV[2])
puts "#{ARGV[1]} implemented"
else
usage "<login|fix|impl>", 0, %w([args])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment