class Pivotal_Hub::Story

Attributes

client[R]
git[R]
label[R]
project[R]

Public Class Methods

new() click to toggle source
# File lib/Story.rb, line 7
def initialize
 if File.exists?('.git')
  @git = Git.open(Dir.pwd)
      @client = TrackerApi::Client.new(token: @git.config('pivotal.api-token'))
      @project  = @client.project(@git.config('pivotal.project-id'))
  @label = @git.config('pivotal.sprint-label')
  @stories = @project.stories(with_label:@label)
  @chores = @stories.select{|story| story.story_type == "chore"}
  @features = @stories.select{|story| story.story_type == "feature"}
  @bugs = @stories.select{|story| story.story_type == "bug"}
  @dod_report = ""
 else
  puts "Ops, you are not in git directory!"
  exit
 end
end

Public Instance Methods

append_bugs() click to toggle source
# File lib/Story.rb, line 98
def append_bugs
  @dod_report << "**Bugs** \n"
  @bugs.each do |story|
    @dod_report << "> ##{story.id} - #{story.name} - #{story.estimate} pontos \n"
  end
  @dod_report << "\n"
end
append_chores() click to toggle source
# File lib/Story.rb, line 106
def append_chores
  @dod_report << "**Chores** \n"
  @chores.each do |story|
    @dod_report << "> ##{story.id} - #{story.name} - #{story.estimate} pontos \n"
  end
  @dod_report << "\n"
end
append_features() click to toggle source
# File lib/Story.rb, line 90
def append_features
  @dod_report << "**Features** \n"
  @features.each do |story|
    @dod_report << "> ##{story.id} - #{story.name} - #{story.estimate} pontos \n"
  end
  @dod_report << "\n"
end
create_and_switch_to_new_branch(ticket_number) click to toggle source
# File lib/Story.rb, line 40
def create_and_switch_to_new_branch ticket_number
  branch_name = "#{ticket_number}_#{@client.me.name}"
  @git.branch(branch_name).checkout
end
generate_dod() click to toggle source
# File lib/Story.rb, line 45
def generate_dod
  stories = get_sprint_stories @label
  valid_stories = stories.select{|story| story.story_type != "release"}
  last_sprint = @label.split(//).last(1)[0].to_i - 1
  last_sprint_label = "#{@label.chop}#{last_sprint}"
  last_sprint_stories = get_sprint_stories last_sprint_label
  valid_stories_last_sprint = last_sprint_stories
                              .select{|story| story.story_type != "release" && story.current_state != "delivered" && story.current_state != "accepted" && story.current_state != "finished"}
  @dod_report << "**DoD - #{@label}** \n"
  @dod_report << "Pontos a serem entregues: #{sprint_total_points stories} \n"
  @dod_report << "Tickets a serem entregues: #{valid_stories.count} \n"
  @dod_report << "Pontos atrasados que serao entregues: #{stories_last_sprint} \n"
  @dod_report << "Tickets atrasados que serao entregues: #{valid_stories_last_sprint.count} \n"
  @dod_report << "\n"

  append_features
  append_bugs
  append_chores

  f = File.new("dod.txt","w")
  f.write(@dod_report)
  f.close()
end
get_backlog_stories() click to toggle source
# File lib/Story.rb, line 36
def get_backlog_stories
  @project.stories(with_state: :unstarted, with_label:@label, limit: 10)
end
get_current_branch() click to toggle source
# File lib/Story.rb, line 32
def get_current_branch
   @git.current_branch
end
get_sprint_stories(label) click to toggle source
# File lib/Story.rb, line 74
def get_sprint_stories label
  @project.stories(with_label:label)
end
sprint_total_points(stories) click to toggle source
# File lib/Story.rb, line 69
def sprint_total_points stories
  valid_stories = stories.select{|story| story.story_type != "release"}
  valid_stories.inject(0){|sum, story| sum += story.estimate}
end
sprint_total_stories() click to toggle source
# File lib/Story.rb, line 78
def sprint_total_stories
  @project.stories(with_label:@label)
end
stories_last_sprint() click to toggle source
# File lib/Story.rb, line 82
def stories_last_sprint
  last_sprint = @label.split(//).last(1)[0].to_i - 1
  last_sprint_label = "#{@label.chop}#{last_sprint}"
  stories = get_sprint_stories last_sprint_label
  valid_stories = stories.select{|story| story.story_type != "release" && story.current_state != "delivered" && story.current_state != "accepted" && story.current_state != "finished"}
  valid_stories.inject(0){|sum, story| sum += story.estimate}
end
update_state(story_id, state) click to toggle source
# File lib/Story.rb, line 24
def update_state story_id, state
      story = @project.story(story_id)
      story.current_state = state
  story.owner_ids = [@client.me.id]
      story.save
  story
end