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
5c2c471a
Commit
5c2c471a
authored
Nov 21, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix WIP system note not being created
parent
e72804ed
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
40 deletions
+95
-40
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+7
-0
app/models/merge_request.rb
app/models/merge_request.rb
+6
-0
app/services/issuable/common_system_notes_service.rb
app/services/issuable/common_system_notes_service.rb
+13
-1
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+0
-14
app/services/system_note_service.rb
app/services/system_note_service.rb
+3
-7
changelogs/unreleased/issue_40374.yml
changelogs/unreleased/issue_40374.yml
+5
-0
spec/services/issuable/common_system_notes_service_spec.rb
spec/services/issuable/common_system_notes_service_spec.rb
+42
-1
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+19
-17
No files found.
app/models/concerns/issuable.rb
View file @
5c2c471a
...
...
@@ -345,4 +345,11 @@ module Issuable
def
first_contribution?
false
end
##
# Overriden in MergeRequest
#
def
wipless_title_changed
(
old_title
)
old_title
!=
title
end
end
app/models/merge_request.rb
View file @
5c2c471a
...
...
@@ -181,6 +181,12 @@ class MergeRequest < ActiveRecord::Base
work_in_progress?
(
title
)
?
title
:
"WIP:
#{
title
}
"
end
# Verifies if title has changed not taking into account WIP prefix
# for merge requests.
def
wipless_title_changed
(
old_title
)
self
.
class
.
wipless_title
(
old_title
)
!=
self
.
wipless_title
end
def
hook_attrs
Gitlab
::
HookData
::
MergeRequestBuilder
.
new
(
self
).
build
end
...
...
app/services/issuable/common_system_notes_service.rb
View file @
5c2c471a
...
...
@@ -41,6 +41,14 @@ module Issuable
end
end
def
create_wip_note
(
old_title
)
return
unless
issuable
.
is_a?
(
MergeRequest
)
if
MergeRequest
.
work_in_progress?
(
old_title
)
!=
issuable
.
work_in_progress?
SystemNoteService
.
handle_merge_request_wip
(
issuable
,
issuable
.
project
,
current_user
)
end
end
def
create_labels_note
(
old_labels
)
added_labels
=
issuable
.
labels
-
old_labels
removed_labels
=
old_labels
-
issuable
.
labels
...
...
@@ -49,8 +57,12 @@ module Issuable
end
def
create_title_change_note
(
old_title
)
create_wip_note
(
old_title
)
if
issuable
.
wipless_title_changed
(
old_title
)
SystemNoteService
.
change_title
(
issuable
,
issuable
.
project
,
current_user
,
old_title
)
end
end
def
create_description_change_note
SystemNoteService
.
change_description
(
issuable
,
issuable
.
project
,
current_user
)
...
...
app/services/merge_requests/base_service.rb
View file @
5c2c471a
...
...
@@ -4,20 +4,6 @@ module MergeRequests
SystemNoteService
.
change_status
(
merge_request
,
merge_request
.
target_project
,
current_user
,
state
,
nil
)
end
def
create_title_change_note
(
issuable
,
old_title
)
removed_wip
=
MergeRequest
.
work_in_progress?
(
old_title
)
&&
!
issuable
.
work_in_progress?
added_wip
=
!
MergeRequest
.
work_in_progress?
(
old_title
)
&&
issuable
.
work_in_progress?
changed_title
=
MergeRequest
.
wipless_title
(
old_title
)
!=
issuable
.
wipless_title
if
removed_wip
SystemNoteService
.
remove_merge_request_wip
(
issuable
,
issuable
.
project
,
current_user
)
elsif
added_wip
SystemNoteService
.
add_merge_request_wip
(
issuable
,
issuable
.
project
,
current_user
)
end
super
if
changed_title
end
def
hook_data
(
merge_request
,
action
,
old_rev:
nil
,
old_labels:
[],
old_assignees:
[],
old_total_time_spent:
nil
)
hook_data
=
merge_request
.
to_hook_data
(
current_user
,
old_labels:
old_labels
,
old_assignees:
old_assignees
,
old_total_time_spent:
old_total_time_spent
)
hook_data
[
:object_attributes
][
:action
]
=
action
...
...
app/services/system_note_service.rb
View file @
5c2c471a
...
...
@@ -241,14 +241,10 @@ module SystemNoteService
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'merge'
))
end
def
remov
e_merge_request_wip
(
noteable
,
project
,
author
)
body
=
'unmarked as a **Work In Progress**'
def
handl
e_merge_request_wip
(
noteable
,
project
,
author
)
prefix
=
noteable
.
work_in_progress?
?
"marked"
:
"unmarked"
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'title'
))
end
def
add_merge_request_wip
(
noteable
,
project
,
author
)
body
=
'marked as a **Work In Progress**'
body
=
"
#{
prefix
}
as a **Work In Progress**"
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'title'
))
end
...
...
changelogs/unreleased/issue_40374.yml
0 → 100644
View file @
5c2c471a
---
title
:
Fix WIP system note not being created
merge_request
:
author
:
type
:
fixed
spec/services/issuable/common_system_notes_service_spec.rb
View file @
5c2c471a
...
...
@@ -18,7 +18,18 @@ describe Issuable::CommonSystemNotesService do
note
=
Note
.
last
expect
(
note
.
note
).
to
match
(
note_text
)
expect
(
note
.
noteable_type
).
to
eq
(
'Issue'
)
expect
(
note
.
noteable_type
).
to
eq
(
issuable
.
class
.
name
)
end
end
shared_examples
'WIP notes creation'
do
|
wip_action
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])
}
it
'creates WIP toggle and title change notes'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
2
)
expect
(
Note
.
first
.
note
).
to
match
(
"
#{
wip_action
}
as a **Work In Progress**"
)
expect
(
Note
.
second
.
note
).
to
match
(
'changed title'
)
end
end
...
...
@@ -45,5 +56,35 @@ describe Issuable::CommonSystemNotesService do
it_behaves_like
'system note creation'
,
{},
'changed milestone'
end
context
'with merge requests WIP note'
do
context
'adding WIP note'
do
let
(
:issuable
)
{
create
(
:merge_request
,
title:
"merge request"
)
}
it_behaves_like
'system note creation'
,
{
title:
"WIP merge request"
},
'marked as a **Work In Progress**'
context
'and changing title'
do
before
do
issuable
.
update_attribute
(
:title
,
"WIP changed title"
)
end
it_behaves_like
'WIP notes creation'
,
'marked'
end
end
context
'removing WIP note'
do
let
(
:issuable
)
{
create
(
:merge_request
,
title:
"WIP merge request"
)
}
it_behaves_like
'system note creation'
,
{
title:
"merge request"
},
'unmarked as a **Work In Progress**'
context
'and changing title'
do
before
do
issuable
.
update_attribute
(
:title
,
"changed title"
)
end
it_behaves_like
'WIP notes creation'
,
'unmarked'
end
end
end
end
end
spec/services/system_note_service_spec.rb
View file @
5c2c471a
...
...
@@ -970,31 +970,33 @@ describe SystemNoteService do
end
end
describe
'.remove_merge_request_wip'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'WIP: Lorem ipsum'
)
}
describe
'.handle_merge_request_wip'
do
context
'adding wip note'
do
let
(
:noteable
)
{
create
(
:merge_request
,
source_project:
project
,
title:
'WIP Lorem ipsum'
)
}
subject
{
described_class
.
remov
e_merge_request_wip
(
noteable
,
project
,
author
)
}
subject
{
described_class
.
handl
e_merge_request_wip
(
noteable
,
project
,
author
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'title'
}
end
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
'un
marked as a **Work In Progress**'
expect
(
subject
.
note
).
to
eq
'
marked as a **Work In Progress**'
end
end
describe
'.add_merge_request_wip
'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
)
}
context
'removing wip note
'
do
let
(
:noteable
)
{
create
(
:merge_request
,
source_
project:
project
,
title:
'Lorem ipsum'
)
}
subject
{
described_class
.
add
_merge_request_wip
(
noteable
,
project
,
author
)
}
subject
{
described_class
.
handle
_merge_request_wip
(
noteable
,
project
,
author
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'title'
}
end
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
'marked as a **Work In Progress**'
expect
(
subject
.
note
).
to
eq
'unmarked as a **Work In Progress**'
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