Skip to content

Instantly share code, notes, and snippets.

@brysgo
Created November 6, 2014 14:47
Show Gist options
  • Save brysgo/145c9a4238461eacdc2c to your computer and use it in GitHub Desktop.
Save brysgo/145c9a4238461eacdc2c to your computer and use it in GitHub Desktop.
Deliver tracker stories finished since last staging deploy
#!/usr/bin/env ruby
require 'pivotal-tracker'
TRACKER_TOKEN = ENV.fetch("TRACKER_TOKEN")
TRACKER_PROJECT_ID = ENV.fetch("TRACKER_PROJECT_ID")
PivotalTracker::Client.token = TRACKER_TOKEN
PivotalTracker::Client.use_ssl = true
project = PivotalTracker::Project.find(TRACKER_PROJECT_ID)
def is_deliverable?(story)
story.current_state == "finished" && ["bug", "feature"].include?(story.story_type)
end
def finished_stories_since_last_deploy
staging_deploy_tag = `git tag | grep staging | tail -n1`.strip
last_staging_deploy_tag = `git tag | grep staging | tail -n2 | head -n1`.strip
git_log = CGI.escape(`git log #{last_staging_deploy_tag}..#{staging_deploy_tag}`)
git_log.scan(/%5B(finish|fix|deliver|complete)[a-z]*\+%23([0-9]+)%5D/i).each do |match|
story_id = match[1]
yield(story_id)
end
end
finished_stories_since_last_deploy do |story_id|
story = project.stories.find(story_id)
if story
if is_deliverable?(story)
puts "Marking #{story.id} as delivered."
story.notes.create(text: "Delivered by staging deploy script.")
story.update(current_state: "delivered")
else
puts "Leaving #{story_id} alone."
end
else
puts "No story with #{story_id} found."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment