class Object

Constants

PLUGINS

Public Instance Methods

create_story(type) click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 105
def create_story(type)
  params = {
    name: ask_for('Story title'),
    description: ask_for('Story description'),
    requested_by_id: requester_id,
    owner_ids: [@user_id],
    story_type: type
  }
  data = @tracker.post("/projects/#{@project_id}/stories", params: params).body
  TrackerApi::Resources::Story.new({ client: @client }.merge(data))
end
estimate() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 87
def estimate
  scale = @project.point_scale.gsub(',', ', ')
  estimate = ask_for("This story needs an estimate first [#{scale}]")
  update_story @story.id, estimate: estimate
end
filter() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 57
def filter
  "current_state:unscheduled,unstarted,rejected mywork:#{@user_initials}"
end
generate_summary() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 44
def generate_summary
  <<-MARKDOWN.gsub(/^    /, '').gsub(/\n+/, "\n\n")
    # #{@story.name}
    #{@story.description}
    #{@story.tasks.map{ |t| "  * #{t.description}" }.join("\n") rescue ''}
    <#{@story.url}>
  MARKDOWN
end
needs_estimation?() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 82
def needs_estimation?
  @story.estimate.nil? &&
  @story.story_type == 'feature' || @project.bugs_and_chores_are_estimatable
end
requester_id() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 117
def requester_id
  question = 'Story requester initials'
  initials = config('pivotal.requester', question, :local, @user_initials).upcase
  user_id_of(initials)
end
select_story() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 61
def select_story
  existing_stories = stories.map do |s|
    s.story_type.upcase.ljust(9) + s.name
  end
  new_story_types = @story_types.inject({}) do |h, (key, type)|
    h.update(key => type.to_s.upcase.ljust(9) + "Create new #{type} story")
  end
  choice = select_one_of('Select story', existing_stories, new_story_types)

  if @story_types.has_key?(choice)
    @story = create_story(@story_types[choice])
  else
    if choice >= 0 and choice < stories.length
      @story = stories[choice]
    else
      abort "No valid story selected."
    end
  end
  estimate if needs_estimation?
end
stories() click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 53
def stories
  @stories ||= @project.stories(filter: filter, limit: 999)
end
update_story(id, attributes) click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 93
def update_story(id, attributes)
  @tracker.put "/projects/#{@project_id}/stories/#{id}", params: attributes
end
user_id_of(initials) click to toggle source
# File lib/git-routines/plugins/pivotal.rb, line 97
def user_id_of(initials)
  membership = @project.memberships.detect{ |m| m.person.initials == initials }
  if membership.nil?
    abort "User with initials #{initials} not found for this project."
  end
  membership.person.id
end