Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jondkinney
Created May 3, 2012 07:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jondkinney/2583888 to your computer and use it in GitHub Desktop.
Save jondkinney/2583888 to your computer and use it in GitHub Desktop.
Allows listing pivotal tracker stories and selecting one to start a new git flow feature or hotfix
require "rubygems"
require "pivotal-tracker"
namespace :pt do
desc "list avail pivotal tracker tix from which to create a git fea branch"
task :list do
def truncate_words(text, length = 5)
return if text == nil
words = text.split()
words = words - %w(feature scenario for in on a an the of so that they be able to are it its with) #remove non critical words (experiment with this)
words[0..(length-1)].join(' ')
end
token = `git config --get pivotal.token`
projectid = `git config --get pivotal.projectid`
PivotalTracker::Client.token = token
PivotalTracker::Client.use_ssl = false
project = PivotalTracker::Project.find projectid
conditions = {:state => ["rejected", "started", "unstarted", "finished"]}
projects = project.stories.all(conditions)
if projects.count > 0
branches = []
projects.each_with_index do |story, index|
name = story.name.downcase
# remove individual offending chars: single quote, double quote, open
# paren, close paren, colon, backslash, forwardslash and replace with
# an empty string (aka nothing)
name.gsub!(/['"\.\(\):\\\/]/,"")
# remove remaining cl.ly links
name.gsub!(/httpclly\S*/,"")
# remove dash and replace with space
name.gsub!(/-/," ")
# do the truncate here, after all the removal & before the _ injection
name = truncate_words(name)
# replace all instances of one or more spaces with _
name.gsub!(/\s+/,"_")
# create final display
display = "#{name}_#{story.id}"
branches[index + 1] = "#{display}"
puts "(#{index + 1}) #{display}"
end
puts ""
puts "(0) EXIT WITHOUT ANY ACTION"
puts ""
puts "For which story do you want to create a new git feature branch?"
puts " Note: type 1,hotfix to create a hotfix for the first story"
input = STDIN.gets.strip
story_num = input.split(",")[0].to_i
story_type = input.split(",")[1]
story_type ||= "feature"
if (1..projects.count).include?(story_num)
`git flow #{story_type} start "#{branches[story_num]}"`
puts ""
puts "Summary of actions:"
puts "- A new branch '#{story_type}/#{branches[story_num]}' was created, based on '#{story_type == 'feature' ? 'develop' : 'master'}'"
puts "- You are now on branch '#{story_type}/#{branches[story_num]}'"
puts ""
puts "Now, start committing on your #{story_type}. When done, use:"
puts ""
puts " git flow #{story_type} finish #{branches[story_num]}"
puts ""
else
exit
end
else
puts "There are no available stories right now!"
end
end
end
@hadees
Copy link

hadees commented Dec 4, 2013

Why did you make this a rake task instead of a git command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment