Class: PivotalIntegration::Util::Story

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal-integration/util/story.rb

Overview

Utilities for dealing with PivotalTracker::Storys

Class Method Summary collapse

Class Method Details

.add_comment(story, comment) ⇒ Object



87
88
89
# File 'lib/pivotal-integration/util/story.rb', line 87

def self.add_comment(story, comment)
  story.notes.create(text: comment)
end

.assign(story, username) ⇒ void

This method returns an undefined value.

Assign story to pivotal tracker member.

Parameters:

  • story (PivotalTracker::Story)

    to be assigned

  • assigned (PivotalTracker::Member)

    user



70
71
72
# 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) ⇒ Object



83
84
85
# File 'lib/pivotal-integration/util/story.rb', line 83

def self.estimate(story, points)
  story.update(estimate: points)
end

.mark(story, state) ⇒ void

This method returns an undefined value.

Marks Pivotal Tracker story with given state

Parameters:

  • story (PivotalTracker::Story)

    to be assigned

  • assigned (PivotalTracker::Member)

    user



79
80
81
# 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) ⇒ Object



23
24
25
# 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) ⇒ void

This method returns an undefined value.

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

Parameters:

  • story (PivotalTracker::Story)

    the story to pretty print



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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).

  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) ⇒ PivotalTracker::Story

Selects a Pivotal Tracker story by doing the following steps:

Parameters:

  • project (PivotalTracker::Project)

    the project to select stories from

  • filter (String, nil) (defaults to: nil)

    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

  • limit (Fixnum) (defaults to: 5)

    The number maximum number of stories the user can choose from

Returns:

  • (PivotalTracker::Story)

    The Pivotal Tracker story selected by the user



101
102
103
104
105
106
107
108
109
# 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