Commit 26ed5b10 authored by Mark Chao's avatar Mark Chao

Merge branch 'fix-iteration-name-on-date-changes' into 'master'

Update iteration title when dates change

See merge request gitlab-org/gitlab!64988
parents cc523010 7a32cdf6
...@@ -55,8 +55,7 @@ module Iterations ...@@ -55,8 +55,7 @@ module Iterations
# we end up having 2020-01-01(beginning of day) - 2020-01-07(end of day) # we end up having 2020-01-01(beginning of day) - 2020-01-07(end of day)
start_date = next_start_date start_date = next_start_date
due_date = start_date + duration.weeks - 1.day due_date = start_date + duration.weeks - 1.day
title = "Iteration #{iteration_number}: #{start_date.strftime(Date::DATE_FORMATS[:long])} - #{due_date.strftime(Date::DATE_FORMATS[:long])}" title = "Iteration #{iteration_number}: #{format_period(start_date, due_date)}"
description = "Auto-generated iteration for cadence##{cadence.id}: #{cadence.title} for period between #{start_date.strftime(Date::DATE_FORMATS[:long])} - #{due_date.strftime(Date::DATE_FORMATS[:long])}."
{ {
iid: iid, iid: iid,
...@@ -67,8 +66,7 @@ module Iterations ...@@ -67,8 +66,7 @@ module Iterations
start_date: start_date, start_date: start_date,
due_date: due_date, due_date: due_date,
state_enum: Iteration::STATE_ENUM_MAP[::Iteration.compute_state(start_date, due_date)], state_enum: Iteration::STATE_ENUM_MAP[::Iteration.compute_state(start_date, due_date)],
title: title, title: title
description: description
} }
end end
...@@ -124,8 +122,11 @@ module Iterations ...@@ -124,8 +122,11 @@ module Iterations
existing_iterations_in_advance.each do |iteration| existing_iterations_in_advance.each do |iteration|
if iteration.duration_in_days != cadence.duration_in_days if iteration.duration_in_days != cadence.duration_in_days
old_title_dates_substring = format_period(iteration.start_date, iteration.due_date)
iteration.start_date = prev_iteration.due_date + 1.day if prev_iteration iteration.start_date = prev_iteration.due_date + 1.day if prev_iteration
iteration.due_date = iteration.start_date + cadence.duration_in_days.days - 1.day iteration.due_date = iteration.start_date + cadence.duration_in_days.days - 1.day
new_title_dates_substring = format_period(iteration.start_date, iteration.due_date)
iteration.title = iteration.title.gsub(old_title_dates_substring, new_title_dates_substring)
end end
prev_iteration = iteration prev_iteration = iteration
...@@ -140,6 +141,12 @@ module Iterations ...@@ -140,6 +141,12 @@ module Iterations
end end
end end
def format_period(start_date, due_date)
format = Date::DATE_FORMATS[:long]
"#{start_date.strftime(format)} - #{due_date.strftime(format)}"
end
def compute_last_run_date def compute_last_run_date
reloaded_last_iteration = cadence_iterations.last reloaded_last_iteration = cadence_iterations.last
run_date = reloaded_last_iteration.due_date - ((cadence.iterations_in_advance - 1) * cadence.duration_in_weeks).weeks if reloaded_last_iteration run_date = reloaded_last_iteration.due_date - ((cadence.iterations_in_advance - 1) * cadence.duration_in_weeks).weeks if reloaded_last_iteration
......
...@@ -159,13 +159,13 @@ RSpec.describe Iterations::Cadences::CreateIterationsInAdvanceService do ...@@ -159,13 +159,13 @@ RSpec.describe Iterations::Cadences::CreateIterationsInAdvanceService do
expect(automated_cadence.reload.last_run_date).to eq(automated_cadence.reload.iterations.last(2).first.due_date) expect(automated_cadence.reload.last_run_date).to eq(automated_cadence.reload.iterations.last(2).first.due_date)
end end
it 'sets the titles correctly based on iterations count and follow-up dates' do it 'sets the title correctly based on iterations count and follow-up dates' do
subject subject
initial_start_date = past_iteration2.due_date + 1.day initial_start_date = past_iteration2.due_date + 1.day
initial_due_date = past_iteration2.due_date + 1.week initial_due_date = past_iteration2.due_date + 1.week
expect(group.reload.iterations.pluck(:title)).to eq([ expect(group.reload.iterations.due_date_order_asc.pluck(:title)).to eq([
'Iteration 1', 'Iteration 1',
'Iteration 2', 'Iteration 2',
"Iteration 3: #{(initial_start_date).strftime(Date::DATE_FORMATS[:long])} - #{initial_due_date.strftime(Date::DATE_FORMATS[:long])}", "Iteration 3: #{(initial_start_date).strftime(Date::DATE_FORMATS[:long])} - #{initial_due_date.strftime(Date::DATE_FORMATS[:long])}",
...@@ -174,6 +174,31 @@ RSpec.describe Iterations::Cadences::CreateIterationsInAdvanceService do ...@@ -174,6 +174,31 @@ RSpec.describe Iterations::Cadences::CreateIterationsInAdvanceService do
]) ])
end end
context 'when cadence changes duration' do
before do
subject
automated_cadence.update!(duration_in_weeks: 3)
automated_cadence.reload
end
it 'adjusts iteration titles for iterations that are autogenerated and have the dates in the title' do
subject
# change duration and expect the titles for iterations containing dates in title to change
described_class.new(user, automated_cadence).execute
initial_start_date = past_iteration2.due_date + 1.day
initial_due_date = past_iteration2.due_date + 1.week
expect(group.reload.iterations.due_date_order_asc.pluck(:title)).to eq([
'Iteration 1',
'Iteration 2',
"Iteration 3: #{(initial_start_date).strftime(Date::DATE_FORMATS[:long])} - #{initial_due_date.strftime(Date::DATE_FORMATS[:long])}",
"Iteration 4: #{(initial_due_date + 1.day).strftime(Date::DATE_FORMATS[:long])} - #{(initial_due_date + 3.weeks).strftime(Date::DATE_FORMATS[:long])}",
"Iteration 5: #{(initial_due_date + 3.weeks + 1.day).strftime(Date::DATE_FORMATS[:long])} - #{(initial_due_date + 6.weeks).strftime(Date::DATE_FORMATS[:long])}"
])
end
end
it 'sets the states correctly based on iterations dates' do it 'sets the states correctly based on iterations dates' do
subject subject
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment