Class: Crab::Rally

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/crab/rally.rb

Instance Method Summary collapse

Methods included from Utilities

#add_or_update_options, #credentials_file, #current_project_name, #sanitize_options, #state_after, #state_before, #state_from, #valid_credentials_file, #valid_project_name

Constructor Details

#initialize(dry_run) ⇒ Rally

Returns a new instance of Rally.



6
7
8
9
10
11
12
13
# File 'lib/crab/rally.rb', line 6

def initialize(dry_run)
  @dry_run = dry_run

  if block_given?
    connect
    yield self
  end
end

Instance Method Details

#connectObject



15
16
17
18
# File 'lib/crab/rally.rb', line 15

def connect
  get_credentials
  @rally = ::RallyRestAPI.new :username => @username, :password => @password
end

#create_story(opts) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/crab/rally.rb', line 98

def create_story(opts)
  if @dry_run
    Crab::DryRun::Story.new opts
  else
    Crab::Story.new(@rally.create(:hierarchical_requirement, opts), @dry_run)
  end
end

#create_test_case(story_id, name, opts) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/crab/rally.rb', line 106

def create_test_case(story_id, name, opts)
  story = find_story_with_id story_id
  opts = {:name => name, :work_product => story.rally_object, :project => story.rally_object.project}.merge(opts)

  if @dry_run
    puts "Would create test case for story with ID #{story_id} with #{opts.inspect}"
  else
    tc = @rally.create(:test_case, opts)
    Crab::TestCase.new(tc, @dry_run)
  end
end

#find_iteration_by_name(name, project) ⇒ Object



86
87
88
# File 'lib/crab/rally.rb', line 86

def find_iteration_by_name(name, project)
  @rally.find(:iteration, :project => project) { equal :name, name }.first
end

#find_iterations(project) ⇒ Object



82
83
84
# File 'lib/crab/rally.rb', line 82

def find_iterations(project)
  @rally.find_all(:iteration, :project => project)
end

#find_project(name) ⇒ Object



78
79
80
# File 'lib/crab/rally.rb', line 78

def find_project(name)
  @rally.find(:project, :fetch => true) { equal :name, name }.first
end

#find_release_by_name(name, project) ⇒ Object



94
95
96
# File 'lib/crab/rally.rb', line 94

def find_release_by_name(name, project)
  @rally.find(:release, :project => project) { equal :name, name }.first
end

#find_releases(project) ⇒ Object



90
91
92
# File 'lib/crab/rally.rb', line 90

def find_releases(project)
  @rally.find_all(:release, :project => project, :fetch => true)
end

#find_stories(project, pattern, opts) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/crab/rally.rb', line 55

def find_stories(project, pattern, opts)
  if pattern.join.empty? && opts.empty?
    return @rally.find_all(:hierarchical_requirement, :fetch => true, :project => project).map {|s| Crab::Story.new(s, @dry_run) }
  end

  rally_stories = @rally.find(:hierarchical_requirement, :fetch => true, :project => project) do
    unless pattern.join.empty?
      _or_ do
        (pattern.map(&:downcase) + pattern.map(&:capitalize)).each do |word|
          contains :name, word
          contains :description, word
          contains :notes, word
        end
      end
    end
    equal :iteration, opts[:iteration] if opts[:iteration]
    equal :release,   opts[:release]   if opts[:release]
    equal :parent,    opts[:parent].rally_object if opts[:parent]
  end

  rally_stories.map {|story| Crab::Story.new(story, @dry_run) }
end

#find_story_with_id(story_id) ⇒ Object



24
25
26
27
28
# File 'lib/crab/rally.rb', line 24

def find_story_with_id story_id
  story = @rally.find(:hierarchical_requirement) { equal :formatted_i_d, story_id }.first
  Trollop::die "Story with ID #{story_id.inspect} not found" if story.nil?
  Crab::Story.new(story, @dry_run)
end

#find_test_case(tc_id) ⇒ Object



118
119
120
# File 'lib/crab/rally.rb', line 118

def find_test_case(tc_id)
  Crab::TestCase.new(@rally.find(:test_case) { equal :formatted_i_d, tc_id }.first, @dry_run)
end

#find_testcases(project, pattern, opts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/crab/rally.rb', line 30

def find_testcases(project, pattern, opts)
  if pattern.join.empty? && opts.empty?
    return @rally.find_all(:test_case, :fetch => true, :project => project).map {|tc| Crab::TestCase.new(tc, @dry_run) }
  end

  rally_testcases = @rally.find(:test_case, :fetch => true, :project => project) do
    unless pattern.join.empty?
      _or_ do
        (pattern.map(&:downcase) + pattern.map(&:capitalize)).each do |word|
          contains :name, word
          contains :description, word
          contains :notes, word
        end
      end
    end
    equal :work_product, opts[:story].rally_object if opts[:story]
    equal :risk,     opts[:risk].capitalize     if opts[:risk]
    equal :method,   opts[:method].capitalize   if opts[:method]
    equal :priority, opts[:priority].capitalize if opts[:priority]
    equal :type,     opts[:type].capitalize     if opts[:type]
  end

  rally_testcases.map {|tc| Crab::TestCase.new(tc, @dry_run) }
end

#get_credentialsObject



20
21
22
# File 'lib/crab/rally.rb', line 20

def get_credentials
  @username, @password = File.read(valid_credentials_file).split /\n/
end