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
Jérome Perrin
gitlab-ce
Commits
effa94bb
Commit
effa94bb
authored
Oct 15, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve SystemNote interface for branch add/restore case
parent
22775c59
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
15 deletions
+19
-15
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+7
-9
app/services/system_note_service.rb
app/services/system_note_service.rb
+9
-3
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+1
-1
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+2
-2
No files found.
app/services/merge_requests/refresh_service.rb
View file @
effa94bb
...
...
@@ -7,11 +7,11 @@ module MergeRequests
@branch_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@fork_merge_requests
=
@project
.
fork_merge_requests
.
opened
@commits
=
[]
@
merge_requests
=
merge_requests_for
_branch
@
source_merge_requests
=
merge_requests_for_source
_branch
# Leave a system note if a branch were deleted/added
if
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
or
Gitlab
::
Git
.
blank_ref?
(
newrev
)
presence
=
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
?
'added'
:
'deleted'
presence
=
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
?
:add
:
:delete
comment_mr_branch_presence_changed
(
presence
)
else
@commits
=
@project
.
repository
.
commits_between
(
oldrev
,
newrev
)
...
...
@@ -81,18 +81,16 @@ module MergeRequests
# Add comment about branches being deleted or added to merge requests
def
comment_mr_branch_presence_changed
(
presence
)
merge_requests
=
merge_requests_for_branch
merge_requests
.
each
do
|
merge_request
|
@source_merge_requests
.
each
do
|
merge_request
|
SystemNoteService
.
change_branch_presence
(
merge_request
,
merge_request
.
project
,
@current_user
,
'source'
,
@branch_name
,
presence
)
:source
,
@branch_name
,
presence
)
end
end
# Add comment about pushing new commits to merge requests
def
comment_mr_with_commits
@merge_requests
.
each
do
|
merge_request
|
@
source_
merge_requests
.
each
do
|
merge_request
|
mr_commit_ids
=
Set
.
new
(
merge_request
.
commits
.
map
(
&
:id
))
new_commits
,
existing_commits
=
@commits
.
partition
do
|
commit
|
...
...
@@ -107,7 +105,7 @@ module MergeRequests
# Call merge request webhook with update branches
def
execute_mr_web_hooks
@merge_requests
.
each
do
|
merge_request
|
@
source_
merge_requests
.
each
do
|
merge_request
|
execute_hooks
(
merge_request
,
'update'
)
end
end
...
...
@@ -116,7 +114,7 @@ module MergeRequests
merge_requests
.
uniq
.
select
(
&
:source_project
)
end
def
merge_requests_for_branch
def
merge_requests_for_
source_
branch
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
@branch_name
).
to_a
merge_requests
+=
@fork_merge_requests
.
where
(
source_branch:
@branch_name
).
to_a
filter_merge_requests
(
merge_requests
)
...
...
app/services/system_note_service.rb
View file @
effa94bb
...
...
@@ -173,9 +173,9 @@ class SystemNoteService
# noteable - Noteable object
# project - Project owning noteable
# author - User performing the change
# branch_type -
'source' or 'target'
# branch_type -
:source or :target
# branch - branch name
# presence -
'deleted' or 'created'
# presence -
:add or :delete
#
# Example Note text:
#
...
...
@@ -183,7 +183,13 @@ class SystemNoteService
#
# Returns the created Note object
def
self
.
change_branch_presence
(
noteable
,
project
,
author
,
branch_type
,
branch
,
presence
)
body
=
"
#{
branch_type
}
branch `
#{
branch
}
`
#{
presence
}
"
.
capitalize
verb
=
if
presence
==
:add
'restored'
else
'deleted'
end
body
=
"
#{
branch_type
.
to_s
}
branch `
#{
branch
}
`
#{
verb
}
"
.
capitalize
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
...
...
spec/services/merge_requests/refresh_service_spec.rb
View file @
effa94bb
...
...
@@ -121,7 +121,7 @@ describe MergeRequests::RefreshService do
it
{
expect
(
@merge_request
.
notes
).
to
be_empty
}
it
{
expect
(
@merge_request
).
to
be_open
}
it
{
expect
(
@fork_merge_request
.
notes
.
last
.
note
).
to
include
(
'Source branch `master`
add
ed'
)
}
it
{
expect
(
@fork_merge_request
.
notes
.
last
.
note
).
to
include
(
'Source branch `master`
restor
ed'
)
}
it
{
expect
(
@fork_merge_request
).
to
be_open
}
end
...
...
spec/services/system_note_service_spec.rb
View file @
effa94bb
...
...
@@ -229,7 +229,7 @@ describe SystemNoteService do
end
describe
'.change_branch'
do
subject
{
described_class
.
change_branch
(
noteable
,
project
,
author
,
'target'
,
old_branch
,
new_branch
)
}
subject
{
described_class
.
change_branch
(
noteable
,
project
,
author
,
:target
,
old_branch
,
new_branch
)
}
let
(
:old_branch
)
{
'old_branch'
}
let
(
:new_branch
)
{
'new_branch'
}
...
...
@@ -243,7 +243,7 @@ describe SystemNoteService do
end
describe
'.change_branch_presence'
do
subject
{
described_class
.
change_branch_presence
(
noteable
,
project
,
author
,
'source'
,
'feature'
,
'deleted'
)
}
subject
{
described_class
.
change_branch_presence
(
noteable
,
project
,
author
,
'source'
,
'feature'
,
:delete
)
}
it_behaves_like
'a system note'
...
...
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