Class: Jira::Auto::Tool::SprintStateController

Inherits:
Object
  • Object
show all
Defined in:
lib/jira/auto/tool/sprint_state_controller.rb

Defined Under Namespace

Modules: SprintState

Constant Summary collapse

STATE_TRANSITIONS =
{
  SprintState::FUTURE => SprintState::ACTIVE,
  SprintState::ACTIVE => SprintState::CLOSED
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jira_client, sprint) ⇒ SprintStateController

Returns a new instance of SprintStateController.



9
10
11
12
# File 'lib/jira/auto/tool/sprint_state_controller.rb', line 9

def initialize(jira_client, sprint)
  @jira_client = jira_client
  @sprint = sprint
end

Instance Attribute Details

#jira_clientObject (readonly)

Returns the value of attribute jira_client.



7
8
9
# File 'lib/jira/auto/tool/sprint_state_controller.rb', line 7

def jira_client
  @jira_client
end

#sprintObject (readonly)

Returns the value of attribute sprint.



7
8
9
# File 'lib/jira/auto/tool/sprint_state_controller.rb', line 7

def sprint
  @sprint
end

Instance Method Details

#transition_state(desired_state) ⇒ Object

TODO: - write unit tests TODO - fix infinite loop in case of invalid/in-existing state



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jira/auto/tool/sprint_state_controller.rb', line 32

def transition_state(desired_state)
  current_state = sprint.state

  loop do
    log.debug do
      "sprint_to_update = #{sprint.name}, current_state = #{current_state} desired_state = #{desired_state}"
    end

    break if current_state == desired_state

    new_state = STATE_TRANSITIONS[current_state]

    update_sprint_state(new_state)

    current_state = new_state
  end
end

#transition_to(desired_state) ⇒ Object



14
15
16
# File 'lib/jira/auto/tool/sprint_state_controller.rb', line 14

def transition_to(desired_state)
  transition_state(desired_state)
end

#update_sprint_state(new_state) ⇒ Object



50
51
52
53
54
# File 'lib/jira/auto/tool/sprint_state_controller.rb', line 50

def update_sprint_state(new_state)
  RequestBuilder::SprintStateUpdater
    .new(jira_client, sprint: sprint, new_state: new_state)
    .run
end