-
-
Save fairchild/17414 to your computer and use it in GitHub Desktop.
shell script to assist in working with lighthouse and git
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 | |
# 2008.10.03 | |
# JD Huntington | |
# shell script to assist in working with lighthouse and git | |
# requires lighthouse api ruby wrapper from http://github.com/Caged/lighthouse-api/tree/master | |
LIB_DIR='~/lib' # Absolute location of lighthouse.rb and lighthouse-api.rb | |
TOKEN='' # Insert your lighthouse token | |
ACCOUNT='' # Insert your lighthouse account name | |
FIXED_STATUS='verify' # Status your tasks should be when they are completed in lighthouse | |
PROJECT_ID=9903 # No easy way to get this I'm afraid...(found using API) | |
$initialized = false | |
$VERBOSE = nil | |
$:.unshift File.expand_path(LIB_DIR) | |
require 'lighthouse' | |
module BugFixing | |
module_function | |
def usage | |
STDERR.puts " | |
THE bug fixing workflow. (set up for #{ACCOUNT}) | |
Workflow: | |
git checkout master | |
bugflow start <bugid> | |
[do some work] | |
bugflow fixed <commit message> | |
hack && ship | |
bugflow shipped | |
Usage: | |
usage display this message | |
open view the active ticket in your default browser [OSX only] | |
start <bugid> create a new branch based on bugid, and assigns to you | |
fixed <commit message> commits all tracked and untracked files with <commit message>, | |
appends lighthouse tags to set to state '#{FIXED_STATUS}' and assigns to 'none' | |
shipped deletes the current working branch | |
" | |
end | |
def load_lighthouse! | |
return if $initialized == true | |
Lighthouse.token = TOKEN | |
Lighthouse.account = ACCOUNT | |
$initialized = true | |
end | |
def open | |
load_lighthouse! | |
url = "http://#{ACCOUNT}.lighthouseapp.com/projects/#{PROJECT_ID}/tickets/#{find_current_ticket}" | |
%x{open "#{url}"} | |
end | |
def fixed commit_msg | |
%x{git add .} | |
commit_string = "#{commit_msg} [##{find_current_ticket} responsible:none state:#{FIXED_STATUS}]" | |
puts %x{git commit -m "#{commit_string}"} | |
end | |
def shipped | |
current = find_current_branch | |
%x{git checkout master} | |
%x{git branch -d #{current}} | |
end | |
def get_user_id | |
load_lighthouse! | |
Lighthouse::Token.find(TOKEN).user_id | |
end | |
def find_current_branch | |
output = %x{git branch} | |
return output.grep(/^\*/).first.strip[2 .. -1] | |
end | |
def find_current_ticket | |
branch = find_current_branch | |
unless branch[0 .. 2] == 'bf-' | |
STDERR.puts "Error - Not working on a bugflow branch" | |
exit! | |
end | |
branch.split('-')[1].to_i | |
end | |
def start bug_id | |
load_lighthouse! | |
ticket = Lighthouse::Ticket.find(bug_id, :params => { :project_id => PROJECT_ID }) | |
new_tagname = "bf-#{ticket.number}-#{ticket.permalink[0 .. 20]}" | |
%x{git checkout -b #{new_tagname}} | |
ticket.assigned_user_id = get_user_id | |
ticket.save | |
puts '' | |
puts "Now working on ticket #{ticket.number} \"#{ticket.title}\" (#{new_tagname})" | |
puts '' | |
end | |
end | |
begin | |
BugFixing.send(*ARGV) | |
rescue ArgumentError | |
STDERR.puts "Wrong number of arguments." | |
rescue | |
STDERR.puts "Command not recognized." | |
BugFixing.usage | |
end | |
# TODO | |
# * Make sure .git exists in current directory | |
# * Make .bugflow so that teams can share configs and use same script for multiple projects | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment