class FlashFlow::IssueTracker::Pivotal
Public Class Methods
new(branches, git, opts={})
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 8 def initialize(branches, git, opts={}) @branches = branches @git = git @timezone = opts['timezone'] || "UTC" @project_id = opts['project_id'] PivotalTracker::Client.token = opts['token'] PivotalTracker::Client.use_ssl = true @release_label_prefix = Regexp.new("^#{opts['release_label_prefix'] || 'release'}", Regexp::IGNORECASE) end
Public Instance Methods
production_deploy()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 41 def production_deploy shipped_branches.each do |branch| branch.stories.to_a.each do |story_id| comment(story_id) end end end
release_keys(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 77 def release_keys(story_id) story = get_story(story_id) return [] unless story && story.labels story.labels.split(",").map(&:strip).select { |label| label =~ @release_label_prefix }.map(&:strip) end
release_notes(hours, file=STDOUT)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 49 def release_notes(hours, file=STDOUT) release_stories = done_and_current_stories.map do |story| shipped_text = has_shipped_text?(story) format_release_data(story.id, story.name, shipped_text) if shipped_text end.compact release_notes = release_by(release_stories, hours) print_release_notes(release_notes, file) end
stories_delivered()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 27 def stories_delivered merged_branches.each do |branch| branch.stories.to_a.each do |story_id| deliver(story_id) end end removed_and_failed_branches.each do |branch| branch.stories.to_a.each do |story_id| undeliver(story_id) end end end
stories_for_release(release_key)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 85 def stories_for_release(release_key) stories_for_label(release_key) end
stories_pushed()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 19 def stories_pushed if merged_working_branch merged_working_branch.stories.to_a.each do |story_id| finish(story_id) end end end
story_deployable?(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 59 def story_deployable?(story_id) story = get_story(story_id) story && story.current_state == 'accepted' end
story_link(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 65 def story_link(story_id) story = get_story(story_id) story.url if story end
story_title(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 71 def story_title(story_id) story = get_story(story_id) story.name if story end
Private Instance Methods
already_has_comment?(story, comment)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 174 def already_has_comment?(story, comment) story.notes.all.map(&:text).detect { |text| text =~ comment } end
comment(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 122 def comment(story_id) story = get_story(story_id) if story unless has_shipped_text?(story) story.notes.create(:text => TimeHelper.with_time_zone(@timezone) { Time.now.strftime(note_time_format) }) end end end
deliver(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 104 def deliver(story_id) story = get_story(story_id) if story && story.current_state == 'finished' story.current_state = 'delivered' story.update end end
done_and_current_stories()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 147 def done_and_current_stories [project.iteration(:done).last(2).map(&:stories) + project.iteration(:current).stories].flatten end
finish(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 113 def finish(story_id) story = get_story(story_id) if story && story.current_state == 'started' story.current_state = 'finished' story.update end end
format_release_data(story_id, story_name, shipped_text)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 139 def format_release_data(story_id, story_name, shipped_text) {id: story_id, title: story_name, time: Time.strptime(shipped_text, note_time_format)} end
get_story(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 169 def get_story(story_id) @stories ||= {} @stories[story_id] ||= project.stories.find(story_id) end
has_shipped_text?(story)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 178 def has_shipped_text?(story) already_has_comment?(story, Regexp.new("^#{note_prefix}")) end
merged_branches()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 186 def merged_branches @branches.select { |b| b.success? } end
merged_working_branch()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 194 def merged_working_branch merged_branches.detect { |b| b.ref == @git.working_branch } end
note_prefix()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 131 def note_prefix 'Shipped to production on' end
note_time_format()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 135 def note_time_format "#{note_prefix} %m/%d/%Y at %H:%M" end
print_release_notes(release_notes, file=nil)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 162 def print_release_notes(release_notes, file=nil) file ||= STDOUT release_notes.each do |story| file.puts "PT##{story[:id]} #{story[:title]} (#{story[:time]})" end end
project()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 91 def project @project ||= PivotalTracker::Project.find(@project_id) end
release_by(release_stories, hours)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 156 def release_by(release_stories, hours) release_stories .select { |story| story[:time] >= (Time.now - hours.to_i*60*60) } .sort_by {|story| story[:time] }.reverse end
removed_and_failed_branches()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 190 def removed_and_failed_branches @branches.select { |b| b.removed? || b.fail? } end
shipped?(branch)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 143 def shipped?(branch) branch.sha && @git.master_branch_contains?(branch.sha) end
shipped_branches()
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 182 def shipped_branches @branches.select { |b| shipped?(b) } end
stories_for_label(label)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 151 def stories_for_label(label) @stories_for_label ||= {} @stories_for_label[label] ||= project.stories.all(label: label).map(&:id) end
undeliver(story_id)
click to toggle source
# File lib/flash_flow/issue_tracker/pivotal.rb, line 95 def undeliver(story_id) story = get_story(story_id) if story && story.current_state == 'delivered' story.current_state = 'finished' story.update end end