class AssistedWorkflow::Addons::Pivotal
Public Class Methods
new(output, options = {})
click to toggle source
Calls superclass method
AssistedWorkflow::Addons::Base::new
# File lib/assisted_workflow/addons/pivotal.rb, line 22 def initialize(output, options = {}) super @client = TrackerApi::Client.new(token: options["token"]) begin @project = @client.project(options["project_id"]) rescue raise AssistedWorkflow::Error, "pivotal project #{options["project_id"]} not found." end @fullname = options["fullname"] @username = options["username"] end
Public Instance Methods
find_story(story_id)
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 35 def find_story(story_id) if story_id.to_i > 0 log "loading story ##{story_id}" PivotalStory.new(@project.story(story_id)) end end
finish_story(story, options = {})
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 54 def finish_story(story, options = {}) log "finishing story ##{story.id}" saved = update_story! story, :current_state => finished_state(story) if saved && options[:note] add_comment_to_story(story, options[:note]) end end
pending_stories(options = {})
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 62 def pending_stories(options = {}) log "loading pending stories" states = ["unstarted"] states << "started" if options[:include_started] filter_str = "state:#{states.join(',')} owned_by:#{@client.me.id}" stories = @project.stories(:filter => filter_str, :limit => 5) stories.map do |story| PivotalStory.new(story) end end
start_story(story, options = {})
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 42 def start_story(story, options = {}) log "starting story ##{story.id}" options.delete(:estimate) if options[:estimate].nil? update_story!(story, options.merge(:current_state => "started")) owner_ids = story.owner_ids if owner_ids.empty? || !owner_ids.include?(@client.me.id) log "assigning story ##{story.id}" update_story!(story, :owner_ids => owner_ids.dup << @client.me.id) end end
valid?()
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 73 def valid? !@project.nil? end
Private Instance Methods
add_comment_to_story(story, text)
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 79 def add_comment_to_story(story, text) url = "/projects/#{story.project_id}/stories/#{story.id}/comments" @client.post(url, params: {:text => text}) rescue TrackerApi::Error => e body = e.response[:body] msg = body["possible_fix"] || body["general_problem"] raise AssistedWorkflow::Error, msg end
finished_state(story)
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 88 def finished_state(story) if story.story_type == "chore" "accepted" else "finished" end end
update_story!(story, attributes)
click to toggle source
# File lib/assisted_workflow/addons/pivotal.rb, line 96 def update_story!(story, attributes) if story begin story.attributes = attributes story.save rescue TrackerApi::Error => e body = e.response[:body] msg = body["possible_fix"] || body["general_problem"] raise AssistedWorkflow::Error, msg end true end end