fairchild (owner)

Fork Of

Revisions

gist: 17414 Download_button fork
public
Description:
shell script to assist in working with lighthouse and git
Public Clone URL: git://gist.github.com/17414.git
Embed All Files: show embed
bugflow #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/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