class PivotalIntegration::Util::Story

Utilities for dealing with +PivotalTracker::Story+s

Constants

CANDIDATE_STATES
CONTENT_WIDTH
LABEL_DESCRIPTION
LABEL_TITLE
LABEL_WIDTH

Public Class Methods

add_comment(story, comment) click to toggle source
# File lib/pivotal-integration/util/story.rb, line 87
def self.add_comment(story, comment)
  story.notes.create(text: comment)
end
assign(story, username) click to toggle source

Assign story to pivotal tracker member.

@param [PivotalTracker::Story] story to be assigned @param [PivotalTracker::Member] assigned user @return [void]

# File lib/pivotal-integration/util/story.rb, line 70
def self.assign(story, username)
  puts "Story assigned to #{username}" if story.update(owned_by: username)
end
estimate(story, points) click to toggle source
# File lib/pivotal-integration/util/story.rb, line 83
def self.estimate(story, points)
  story.update(estimate: points)
end
mark(story, state) click to toggle source

Marks Pivotal Tracker story with given state

@param [PivotalTracker::Story] story to be assigned @param [PivotalTracker::Member] assigned user @return [void]

# File lib/pivotal-integration/util/story.rb, line 79
def self.mark(story, state)
  puts "Changed state to #{state}" if story.update(current_state: state)
end
new(project, name, type) click to toggle source
# File lib/pivotal-integration/util/story.rb, line 23
def self.new(project, name, type)
  project.stories.create(name: name, story_type: type)
end
pretty_print(story) click to toggle source

Print a human readable version of a story. This pretty prints the title, description, and notes for the story.

@param [PivotalTracker::Story] story the story to pretty print @return [void]

# File lib/pivotal-integration/util/story.rb, line 32
def self.pretty_print(story)
  print_label 'ID'
  print_value story.id

  print_label 'Project'
  print_value PivotalTracker::Project.find(story.project_id).account

  print_label LABEL_TITLE
  print_value story.name

  description = story.description
  if !description.nil? && !description.empty?
    print_label 'Description'
    print_value description
  end

  print_label 'Type'
  print_value story.story_type.titlecase

  print_label 'State'
  print_value story.current_state.titlecase

  print_label 'Estimate'
  print_value story.estimate == -1 ? 'Unestimated' : story.estimate

  PivotalTracker::Note.all(story).sort_by { |note| note.noted_at }.each_with_index do |note, index|
    print_label "Note #{index + 1}"
    print_value note.text
  end

  puts
end
select_story(project, filter = nil, limit = 5) click to toggle source

Selects a Pivotal Tracker story by doing the following steps:

@param [PivotalTracker::Project] project the project to select stories from @param [String, nil] filter a filter for selecting the story to start. This

filter can be either:
* a story id: selects the story represented by the id
* a story type (feature, bug, chore): offers the user a selection of stories of the given type
* +nil+: offers the user a selection of stories of all types

@param [Fixnum] limit The number maximum number of stories the user can choose from @return [PivotalTracker::Story] The Pivotal Tracker story selected by the user

# File lib/pivotal-integration/util/story.rb, line 101
def self.select_story(project, filter = nil, limit = 5)
  if filter =~ /[[:digit:]]/
    story = project.stories.find filter.to_i
  else
    story = find_story project, filter, limit
  end

  story
end

Private Class Methods

find_story(project, type, limit) click to toggle source
# File lib/pivotal-integration/util/story.rb, line 143
def self.find_story(project, type, limit)
  criteria = {
    :current_state => CANDIDATE_STATES
  }
  if type
    criteria[:story_type] = type
  end

  candidates = project.stories.all(criteria).sort_by{ |s| s.owned_by == @user ? 1 : 0 }.slice(0..limit)
  if candidates.length == 1
    story = candidates[0]
  else
    story = choose do |menu|
      menu.prompt = 'Choose story to start: '

      candidates.each do |story|
        name = story.owned_by ? '[%s] ' % story.owned_by : ''
        name += type ? story.name : '%-7s %s' % [story.story_type.upcase, story.name]
        menu.choice(name) { story }
      end
    end

    puts
  end

  story
end
print_label(label) click to toggle source
print_value(value) click to toggle source