Class: Jira::Auto::Tool::TeamSprintTicketDispatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jira_client, tickets, sprint_prefixes) ⇒ TeamSprintTicketDispatcher

Returns a new instance of TeamSprintTicketDispatcher.



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

def initialize(jira_client, tickets, sprint_prefixes)
  @jira_client = jira_client
  @tickets = tickets
  @sprint_prefixes = sprint_prefixes
end

Instance Attribute Details

#jira_clientObject (readonly)

Returns the value of attribute jira_client.



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

def jira_client
  @jira_client
end

#sprint_prefixesObject (readonly)

Returns the value of attribute sprint_prefixes.



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

def sprint_prefixes
  @sprint_prefixes
end

#ticketsObject (readonly)

Returns the value of attribute tickets.



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

def tickets
  @tickets
end

Instance Method Details

#dispatch_ticketsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 15

def dispatch_tickets
  per_team_tickets do |team, tickets|
    log.debug { "#{team}: dispatching tickets #{tickets.collect(&:key).join(", ")}" }

    sprint_prefix_matching_team = sprint_prefix_for(team)

    if sprint_prefix_matching_team.nil?
      log.warn { team_sprint_prefix_mapper.no_matching_sprint_prefix_for_team_message(team) }
    else
      dispatch_tickets_to_prefix_sprints(sprint_prefix_matching_team, tickets)
    end
  end
end

#dispatch_tickets_to_prefix_sprints(prefix_name, tickets) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 33

def dispatch_tickets_to_prefix_sprints(prefix_name, tickets)
  prefix = sprint_prefixes.find { |sprint_prefix| sprint_prefix.name == prefix_name }

  tickets.each do |ticket|
    matched_sprint = match_ticket_to_prefix_sprint(prefix, ticket)

    ticket.sprint = matched_sprint if matched_sprint
  end
end

#first_sprint_when_overdue_ticket(ticket_start_time, prefix) ⇒ Object



52
53
54
55
56
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 52

def first_sprint_when_overdue_ticket(ticket_start_time, prefix)
  first_sprint = prefix.sprints.first

  ticket_start_time < first_sprint.start_date ? first_sprint : nil
end

#match_ticket_to_prefix_sprint(prefix, ticket) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 43

def match_ticket_to_prefix_sprint(prefix, ticket)
  ticket_start_time = Time.parse(ticket.expected_start_date).end_of_day

  first_sprint_when_overdue_ticket(ticket_start_time, prefix) ||
    prefix.sprints.find do |sprint|
      ticket_start_time.between?(sprint.start_date, sprint.end_date)
    end
end

#per_team_ticketsObject



58
59
60
61
62
63
64
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 58

def per_team_tickets(&)
  return enum_for(:per_team_tickets) unless block_given?

  team_ticket_map = tickets.group_by(&:implementation_team)

  team_ticket_map.each(&)
end

#sprint_prefix_for(team) ⇒ Object



29
30
31
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 29

def sprint_prefix_for(team)
  team_sprint_prefix_mapper.fetch_for(team)
end

#team_sprint_prefix_mapperObject



66
67
68
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 66

def team_sprint_prefix_mapper
  TeamSprintPrefixMapper.new(teams, sprint_prefixes)
end

#teamsObject



70
71
72
# File 'lib/jira/auto/tool/team_sprint_ticket_dispatcher.rb', line 70

def teams
  tickets.collect(&:implementation_team).uniq.sort
end