Class: AssistedWorkflow::Addons::Pivotal

Inherits:
Base
  • Object
show all
Defined in:
lib/assisted_workflow/addons/pivotal.rb

Instance Method Summary collapse

Methods inherited from Base

get_required_options, #name, required_options

Constructor Details

#initialize(output, options = {}) ⇒ Pivotal

Returns a new instance of Pivotal.



22
23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Method Details

#find_story(story_id) ⇒ Object



35
36
37
38
39
40
# 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 = {}) ⇒ Object



54
55
56
57
58
59
60
# 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 = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# 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 = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# 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?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/assisted_workflow/addons/pivotal.rb', line 73

def valid?
  !@project.nil?
end