Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
be4b01a8
Commit
be4b01a8
authored
Aug 02, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bulk update epics when milestone date changes
parent
ed0c9424
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
4 deletions
+35
-4
ee/app/models/ee/epic.rb
ee/app/models/ee/epic.rb
+0
-2
ee/app/services/ee/milestones/update_service.rb
ee/app/services/ee/milestones/update_service.rb
+32
-2
ee/spec/services/milestones/update_service_spec.rb
ee/spec/services/milestones/update_service_spec.rb
+3
-0
No files found.
ee/app/models/ee/epic.rb
View file @
be4b01a8
...
...
@@ -170,8 +170,6 @@ module EE
super
.
merge
(
label_url_method: :group_epics_url
)
end
private
def
fetch_milestone_date_data
sql
=
<<~
SQL
SELECT milestones.id, milestones.start_date, milestones.due_date FROM milestones
...
...
ee/app/services/ee/milestones/update_service.rb
View file @
be4b01a8
...
...
@@ -9,12 +9,42 @@ module EE
def
execute
(
milestone
)
super
::
Epic
.
joins
(
:issues
).
where
(
issues:
{
milestone_id:
milestone
.
id
}).
each
do
|
epic
|
epic
.
update_dates
if
milestone
.
previous_changes
.
key?
(
:start_date
)
||
milestone
.
previous_changes
.
key?
(
:due_date
)
update_epics
(
milestone
)
end
milestone
end
private
def
update_epics
(
milestone
)
groups
=
::
Epic
.
joins
(
:issues
).
includes
(
:issues
).
where
(
issues:
{
milestone_id:
milestone
.
id
}).
group_by
do
|
epic
|
milestone_ids
=
epic
.
issues
.
map
(
&
:milestone_id
)
milestone_ids
.
compact!
milestone_ids
.
uniq!
milestone_ids
end
groups
.
each
do
|
milestone_ids
,
epics
|
data
=
epics
.
first
.
fetch_milestone_date_data
::
Epic
.
where
(
id:
epics
.
map
(
&
:id
)).
update_all
(
[
%{
start_date = CASE WHEN start_date_is_fixed = true THEN start_date ELSE ? END,
start_date_sourcing_milestone_id = ?,
end_date = CASE WHEN due_date_is_fixed = true THEN end_date ELSE ? END,
due_date_sourcing_milestone_id = ?
}
,
data
[
:start_date
],
data
[
:start_date_sourcing_milestone_id
],
data
[
:due_date
],
data
[
:due_date_sourcing_milestone_id
]
]
)
end
end
end
end
end
ee/spec/services/milestones/update_service_spec.rb
View file @
be4b01a8
...
...
@@ -17,7 +17,10 @@ describe Milestones::UpdateService do
epic
.
reload
expect
(
epic
.
start_date
).
to
eq
(
nil
)
expect
(
epic
.
start_date_sourcing_milestone
).
to
eq
(
nil
)
expect
(
epic
.
due_date
).
to
eq
(
due_date
)
expect
(
epic
.
due_date_sourcing_milestone
).
to
eq
(
milestone
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment