class PivotalCli::Tracker

Attributes

projects[RW]
username[RW]

Public Instance Methods

config_file() click to toggle source
# File lib/pivotal_cli/tracker.rb, line 7
def config_file
  @config_file ||= "#{ENV['HOME']}/.pivotal"
end
create_story(story) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 40
def create_story(story)
  story.story_type = 'feature'
  story.owned_by = username
  story.create # Return a new story object (with id)
end
deliver(story) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 58
def deliver(story)
  story.update(current_state: 'delivered')
end
find_story(story_id) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 31
def find_story(story_id)
  projects.each do |project|
    story = project.stories.find(story_id)
    return story unless story.nil?
  end

  nil
end
finish(story) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 54
def finish(story)
  story.update(current_state: 'finished')
end
load_configuration() click to toggle source
# File lib/pivotal_cli/tracker.rb, line 62
def load_configuration
  File.open(config_file, 'r') do |file|
    lines = file.readlines
    @username   = lines[0].strip
    token       = lines[2].strip
    project_ids = lines[1].split(',').map(&:strip)

    PivotalTracker::Client.token = token
    PivotalTracker::Client.use_ssl = true
    @projects = project_ids.map { |project_id| PivotalTracker::Project.find(project_id) }
  end
end
my_stories_per_project() click to toggle source
# File lib/pivotal_cli/tracker.rb, line 24
def my_stories_per_project
  projects.map do |project|
    stories = project.stories.all(owned_by: username).reject { |s| s.current_state =~ /accepted/ }
    [project.id, project.name, stories]
  end
end
set_points(story, points) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 46
def set_points(story, points)
  story.update(estimate: points)
end
setup(username, project_ids, token) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 15
def setup(username, project_ids, token)
  username = username.strip
  File.open(config_file, 'w') do |file|
    file.puts(username)
    file.puts(project_ids)
    file.puts(token)
  end
end
setup_complete?() click to toggle source
# File lib/pivotal_cli/tracker.rb, line 11
def setup_complete?
  File.exists?(config_file)
end
start(story) click to toggle source
# File lib/pivotal_cli/tracker.rb, line 50
def start(story)
  story.update(current_state: 'started')
end