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
Léo-Paul Géneau
gitlab-ce
Commits
85e0b994
Commit
85e0b994
authored
Dec 14, 2016
by
twonegatives
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notify the user who set auto-merge when merge conflict occurs
parent
f14228f0
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
52 additions
and
7 deletions
+52
-7
app/helpers/todos_helper.rb
app/helpers/todos_helper.rb
+1
-0
app/models/merge_request.rb
app/models/merge_request.rb
+4
-0
app/models/todo.rb
app/models/todo.rb
+7
-1
app/services/todo_service.rb
app/services/todo_service.rb
+14
-1
app/views/dashboard/todos/_todo.html.haml
app/views/dashboard/todos/_todo.html.haml
+1
-1
changelogs/unreleased/23524-notify-automerge-user-of-failed-build.yml
...nreleased/23524-notify-automerge-user-of-failed-build.yml
+3
-3
spec/factories/todos.rb
spec/factories/todos.rb
+4
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+9
-1
spec/services/todo_service_spec.rb
spec/services/todo_service_spec.rb
+9
-0
No files found.
app/helpers/todos_helper.rb
View file @
85e0b994
...
@@ -14,6 +14,7 @@ module TodosHelper
...
@@ -14,6 +14,7 @@ module TodosHelper
when
Todo
::
BUILD_FAILED
then
'The build failed for'
when
Todo
::
BUILD_FAILED
then
'The build failed for'
when
Todo
::
MARKED
then
'added a todo for'
when
Todo
::
MARKED
then
'added a todo for'
when
Todo
::
APPROVAL_REQUIRED
then
'set you as an approver for'
when
Todo
::
APPROVAL_REQUIRED
then
'set you as an approver for'
when
Todo
::
UNMERGEABLE
then
'Could not merge'
end
end
end
end
...
...
app/models/merge_request.rb
View file @
85e0b994
...
@@ -91,6 +91,10 @@ class MergeRequest < ActiveRecord::Base
...
@@ -91,6 +91,10 @@ class MergeRequest < ActiveRecord::Base
around_transition
do
|
merge_request
,
transition
,
block
|
around_transition
do
|
merge_request
,
transition
,
block
|
Gitlab
::
Timeless
.
timeless
(
merge_request
,
&
block
)
Gitlab
::
Timeless
.
timeless
(
merge_request
,
&
block
)
end
end
after_transition
unchecked: :cannot_be_merged
do
|
merge_request
,
transition
|
TodoService
.
new
.
merge_request_became_unmergeable
(
merge_request
)
end
end
end
validates
:source_project
,
presence:
true
,
unless:
[
:allow_broken
,
:importing?
,
:closed_without_fork?
]
validates
:source_project
,
presence:
true
,
unless:
[
:allow_broken
,
:importing?
,
:closed_without_fork?
]
...
...
app/models/todo.rb
View file @
85e0b994
...
@@ -6,13 +6,15 @@ class Todo < ActiveRecord::Base
...
@@ -6,13 +6,15 @@ class Todo < ActiveRecord::Base
BUILD_FAILED
=
3
BUILD_FAILED
=
3
MARKED
=
4
MARKED
=
4
APPROVAL_REQUIRED
=
5
# This is an EE-only feature
APPROVAL_REQUIRED
=
5
# This is an EE-only feature
UNMERGEABLE
=
6
ACTION_NAMES
=
{
ACTION_NAMES
=
{
ASSIGNED
=>
:assigned
,
ASSIGNED
=>
:assigned
,
MENTIONED
=>
:mentioned
,
MENTIONED
=>
:mentioned
,
BUILD_FAILED
=>
:build_failed
,
BUILD_FAILED
=>
:build_failed
,
MARKED
=>
:marked
,
MARKED
=>
:marked
,
APPROVAL_REQUIRED
=>
:approval_required
APPROVAL_REQUIRED
=>
:approval_required
,
UNMERGEABLE
=>
:unmergeable
}
}
belongs_to
:author
,
class_name:
"User"
belongs_to
:author
,
class_name:
"User"
...
@@ -66,6 +68,10 @@ class Todo < ActiveRecord::Base
...
@@ -66,6 +68,10 @@ class Todo < ActiveRecord::Base
end
end
end
end
def
unmergeable?
action
==
UNMERGEABLE
end
def
build_failed?
def
build_failed?
action
==
BUILD_FAILED
action
==
BUILD_FAILED
end
end
...
...
app/services/todo_service.rb
View file @
85e0b994
...
@@ -124,6 +124,14 @@ class TodoService
...
@@ -124,6 +124,14 @@ class TodoService
mark_pending_todos_as_done
(
merge_request
,
merge_request
.
merge_user
)
if
merge_request
.
merge_when_build_succeeds?
mark_pending_todos_as_done
(
merge_request
,
merge_request
.
merge_user
)
if
merge_request
.
merge_when_build_succeeds?
end
end
# When a merge request could not be automatically merged due to its unmergeable state we should:
#
# * create a todo for a merge_user
#
def
merge_request_became_unmergeable
(
merge_request
)
create_unmergeable_todo
(
merge_request
,
merge_request
.
merge_user
)
if
merge_request
.
merge_when_build_succeeds?
end
# When create a note we should:
# When create a note we should:
#
#
# * mark all pending todos related to the noteable for the note author as done
# * mark all pending todos related to the noteable for the note author as done
...
@@ -245,6 +253,11 @@ class TodoService
...
@@ -245,6 +253,11 @@ class TodoService
create_todos
(
todo_author
,
attributes
)
create_todos
(
todo_author
,
attributes
)
end
end
def
create_unmergeable_todo
(
merge_request
,
merge_user
)
attributes
=
attributes_for_todo
(
merge_request
.
project
,
merge_request
,
merge_user
,
Todo
::
UNMERGEABLE
)
create_todos
(
merge_user
,
attributes
)
end
def
attributes_for_target
(
target
)
def
attributes_for_target
(
target
)
attributes
=
{
attributes
=
{
project_id:
target
.
project
.
id
,
project_id:
target
.
project
.
id
,
...
...
app/views/dashboard/todos/_todo.html.haml
View file @
85e0b994
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
.todo-item.todo-block
.todo-item.todo-block
.todo-title.title
.todo-title.title
-
unless
todo
.
build_failed?
-
unless
todo
.
build_failed?
||
todo
.
unmergeable?
=
todo_target_state_pill
(
todo
)
=
todo_target_state_pill
(
todo
)
%span
.author-name
%span
.author-name
...
...
changelogs/unreleased/23524-notify-automerge-user-of-failed-build.yml
View file @
85e0b994
---
---
title
:
Create a TODO for user who set auto-merge when a build fails
title
:
Create a TODO for user who set auto-merge when a build fails
, merge conflict occurs
merge_request
:
merge_request
:
8056
author
:
author
:
twonegatives
spec/factories/todos.rb
View file @
85e0b994
...
@@ -27,6 +27,10 @@ FactoryGirl.define do
...
@@ -27,6 +27,10 @@ FactoryGirl.define do
action
{
Todo
::
APPROVAL_REQUIRED
}
action
{
Todo
::
APPROVAL_REQUIRED
}
end
end
trait
:unmergeable
do
action
{
Todo
::
UNMERGEABLE
}
end
trait
:done
do
trait
:done
do
state
:done
state
:done
end
end
...
...
spec/models/merge_request_spec.rb
View file @
85e0b994
...
@@ -740,10 +740,12 @@ describe MergeRequest, models: true do
...
@@ -740,10 +740,12 @@ describe MergeRequest, models: true do
subject
{
create
(
:merge_request
,
source_project:
project
,
merge_status: :unchecked
)
}
subject
{
create
(
:merge_request
,
source_project:
project
,
merge_status: :unchecked
)
}
context
'when it is not broken and has no conflicts'
do
context
'when it is not broken and has no conflicts'
do
it
'is marked as mergeable'
do
before
do
allow
(
subject
).
to
receive
(
:broken?
)
{
false
}
allow
(
subject
).
to
receive
(
:broken?
)
{
false
}
allow
(
project
.
repository
).
to
receive
(
:can_be_merged?
).
and_return
(
true
)
allow
(
project
.
repository
).
to
receive
(
:can_be_merged?
).
and_return
(
true
)
end
it
'is marked as mergeable'
do
expect
{
subject
.
check_if_can_be_merged
}.
to
change
{
subject
.
merge_status
}.
to
(
'can_be_merged'
)
expect
{
subject
.
check_if_can_be_merged
}.
to
change
{
subject
.
merge_status
}.
to
(
'can_be_merged'
)
end
end
end
end
...
@@ -754,6 +756,12 @@ describe MergeRequest, models: true do
...
@@ -754,6 +756,12 @@ describe MergeRequest, models: true do
it
'becomes unmergeable'
do
it
'becomes unmergeable'
do
expect
{
subject
.
check_if_can_be_merged
}.
to
change
{
subject
.
merge_status
}.
to
(
'cannot_be_merged'
)
expect
{
subject
.
check_if_can_be_merged
}.
to
change
{
subject
.
merge_status
}.
to
(
'cannot_be_merged'
)
end
end
it
'creates Todo on unmergeability'
do
expect_any_instance_of
(
TodoService
).
to
receive
(
:merge_request_became_unmergeable
).
with
(
subject
)
subject
.
check_if_can_be_merged
end
end
end
context
'when it has conflicts'
do
context
'when it has conflicts'
do
...
...
spec/services/todo_service_spec.rb
View file @
85e0b994
...
@@ -489,6 +489,15 @@ describe TodoService, services: true do
...
@@ -489,6 +489,15 @@ describe TodoService, services: true do
end
end
end
end
describe
'#merge_request_became_unmergeable'
do
it
'creates a pending todo for a merge_user'
do
mr_unassigned
.
update
(
merge_when_build_succeeds:
true
,
merge_user:
admin
)
service
.
merge_request_became_unmergeable
(
mr_unassigned
)
should_create_todo
(
user:
admin
,
author:
admin
,
target:
mr_unassigned
,
action:
Todo
::
UNMERGEABLE
)
end
end
describe
'#mark_todo'
do
describe
'#mark_todo'
do
it
'creates a todo from a merge request'
do
it
'creates a todo from a merge request'
do
service
.
mark_todo
(
mr_unassigned
,
author
)
service
.
mark_todo
(
mr_unassigned
,
author
)
...
...
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