Class: GitPivotalTrackerIntegration::Util::Story

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

Overview

Utilities for dealing with PivotalTracker::Storys

Constant Summary collapse

CANDIDATE_STATES =
%w(rejected unstarted unscheduled).freeze
LABEL_DESCRIPTION =
'Description'.freeze
LABEL_TITLE =
'Title'.freeze
LABEL_WIDTH =
(LABEL_DESCRIPTION.length + 2).freeze
CONTENT_WIDTH =
(HighLine.new.output_cols - LABEL_WIDTH).freeze

Class Method Summary collapse

Class Method Details

.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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/git-pivotal-tracker-integration/util/story.rb', line 33

def self.pretty_print(story)
  print_label LABEL_TITLE
  print_value story.name

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

  story.comments.sort_by{ |comment| comment.updated_at }.each_with_index do |comment, index|
    print_label "Note #{index + 1}"
    print_value comment.text
  end

  puts
end

.select_release(project, filter = 'b', limit = 10) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/git-pivotal-tracker-integration/util/story.rb', line 89

def self.select_release(project, filter = 'b', limit = 10)
  if filter =~ /[[:digit:]]/
    story = project.story filter.to_i
    if story.story_type != "release"
      $LOG.fatal("Specified story##{filter} is not a valid release story")
      puts "Specified story##{filter} is not a valid release story"
      abort 'FAIL'
    end
  else
    story = find_release_story project, filter, limit
  end

  story
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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/git-pivotal-tracker-integration/util/story.rb', line 62

def self.select_story(project, filter = nil, limit = 5)
  story = nil

  if filter =~ /[[:digit:]]/
    story = project.story filter.to_i
  else
    # story type from (feature, bug, chore)
    # state from (rejected unstarted unscheduled)
    # if story type is "feature", then retrieve only estimated ones.
    criteria = " state:unstarted,rejected,unscheduled,planned"

    if %w(feature bug chore).include?(filter)
      criteria << " type:#{filter}"
      criteria << " -estimate:-1" if filter == "feature"
    else
      criteria << " type:feature,bug,chore"
    end

    candidates  = project.stories(filter: criteria, limit: limit)
    #limit is not working as expected. Need to find the reason. For now handle via ruby
    candidates  = candidates[0...5]
    story       = choose_story(candidates) unless candidates.empty?
  end

  story
end