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
0
Merge Requests
0
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
Kazuhiko Shiozaki
gitlab-ce
Commits
7bed6ee2
Commit
7bed6ee2
authored
Feb 16, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Marks pending tasks for an user as done when he edit a MR
parent
802bf6d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
1 deletion
+75
-1
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+21
-0
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+54
-1
No files found.
app/services/merge_requests/update_service.rb
View file @
7bed6ee2
...
@@ -15,6 +15,10 @@ module MergeRequests
...
@@ -15,6 +15,10 @@ module MergeRequests
end
end
def
handle_changes
(
merge_request
,
options
=
{})
def
handle_changes
(
merge_request
,
options
=
{})
if
have_changes?
(
merge_request
,
options
)
task_service
.
mark_as_done
(
merge_request
,
current_user
)
end
if
merge_request
.
previous_changes
.
include?
(
'target_branch'
)
if
merge_request
.
previous_changes
.
include?
(
'target_branch'
)
create_branch_change_note
(
merge_request
,
'target'
,
create_branch_change_note
(
merge_request
,
'target'
,
merge_request
.
previous_changes
[
'target_branch'
].
first
,
merge_request
.
previous_changes
[
'target_branch'
].
first
,
...
@@ -44,5 +48,22 @@ module MergeRequests
...
@@ -44,5 +48,22 @@ module MergeRequests
def
close_service
def
close_service
MergeRequests
::
CloseService
MergeRequests
::
CloseService
end
end
private
def
have_changes?
(
merge_request
,
options
=
{})
valid_attrs
=
[
:title
,
:description
,
:assignee_id
,
:milestone_id
,
:target_branch
]
attrs_changed
=
valid_attrs
.
any?
do
|
attr
|
merge_request
.
previous_changes
.
include?
(
attr
.
to_s
)
end
old_labels
=
options
[
:old_labels
]
labels_changed
=
old_labels
&&
merge_request
.
labels
!=
old_labels
if
attrs_changed
||
labels_changed
task_service
.
mark_as_done
(
merge_request
,
current_user
)
end
end
end
end
end
end
spec/services/merge_requests/update_service_spec.rb
View file @
7bed6ee2
...
@@ -103,11 +103,35 @@ describe MergeRequests::UpdateService, services: true do
...
@@ -103,11 +103,35 @@ describe MergeRequests::UpdateService, services: true do
create
(
:pending_assigned_task
,
user:
user
,
project:
project
,
target:
merge_request
,
author:
user2
)
create
(
:pending_assigned_task
,
user:
user
,
project:
project
,
target:
merge_request
,
author:
user2
)
end
end
context
'when the title change'
do
before
do
update_merge_request
({
title:
'New title'
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
).
to
be_done
end
end
context
'when the description change'
do
before
do
update_merge_request
({
description:
'Also please fix'
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
).
to
be_done
end
end
context
'when is reassigned'
do
context
'when is reassigned'
do
before
do
before
do
update_merge_request
({
assignee:
user2
})
update_merge_request
({
assignee:
user2
})
end
end
it
'marks previous assignee pending tasks as done'
do
expect
(
pending_task
.
reload
).
to
be_done
end
it
'creates a pending task for new assignee'
do
it
'creates a pending task for new assignee'
do
attributes
=
{
attributes
=
{
project:
project
,
project:
project
,
...
@@ -121,6 +145,36 @@ describe MergeRequests::UpdateService, services: true do
...
@@ -121,6 +145,36 @@ describe MergeRequests::UpdateService, services: true do
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
expect
(
Task
.
where
(
attributes
).
count
).
to
eq
1
end
end
end
end
context
'when the milestone change'
do
before
do
update_merge_request
({
milestone:
create
(
:milestone
)
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
).
to
be_done
end
end
context
'when the labels change'
do
before
do
update_merge_request
({
label_ids:
[
label
.
id
]
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
).
to
be_done
end
end
context
'when the target branch change'
do
before
do
update_merge_request
({
target_branch:
'target'
})
end
it
'marks pending tasks as done'
do
expect
(
pending_task
.
reload
).
to
be_done
end
end
end
end
context
'when MergeRequest has tasks'
do
context
'when MergeRequest has tasks'
do
...
@@ -155,6 +209,5 @@ describe MergeRequests::UpdateService, services: true do
...
@@ -155,6 +209,5 @@ describe MergeRequests::UpdateService, services: true do
end
end
end
end
end
end
end
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