Class: Rallycat::List

Inherits:
Object
  • Object
show all
Defined in:
lib/rallycat/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ List

Returns a new instance of List.



4
5
6
7
# File 'lib/rallycat/list.rb', line 4

def initialize(api)
  @api = api
  @config = Config.new
end

Instance Method Details

#iterations(project_name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rallycat/list.rb', line 9

def iterations(project_name)
  project_name ||= @config['project']

  validate_arg project_name, 'Project name is required.'

  project = find_project(project_name)

  iterations = @api.find_all(:iteration, {
    :project  => project,
    :order    => 'StartDate desc',
    :pagesize => 10
  }).results

  if iterations.count == 0
    return "No iterations could be found for project #{project_name}."
  end

  iteration_names = iterations.map(&:name).uniq

  <<-LIST
# 5 Most recent iterations for "#{project_name}"

#{iteration_names.join("\n")}

  LIST
end

#stories(project_name, iteration_name) ⇒ Object



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
64
65
66
67
68
69
# File 'lib/rallycat/list.rb', line 36

def stories(project_name, iteration_name)
  project_name ||= @config['project']

  validate_arg project_name,   'Project name is required.'
  validate_arg iteration_name, 'Iteration name is required.'

  project   = find_project(project_name)
  iteration = find_iteration(iteration_name, project)

  stories = @api.find(:hierarchical_requirement, {
    :project  => project,
    :pagesize => 100,
    :fetch    => true
  }) { equal :iteration, iteration }.results

  stories += @api.find(:defect, {
    :project  => project,
    :pagesize => 100,
    :fetch    => true
  }) { equal :iteration, iteration }.results

  if stories.count == 0
    return %{No stories could be found for iteration "#{iteration_name}".}
  end

  list = %{# Stories for iteration "#{iteration_name}" - "#{project_name}"\n\n}

  stories.each do |story|
    state = story.schedule_state == 'In-Progress' ? 'P' : story.schedule_state.split('')[0]
    list += "* [#{story.formatted_i_d}] [#{state}] #{story.name}\n"
  end

  list += "\n"
end