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
Boxiang Sun
gitlab-ce
Commits
df44c590
Commit
df44c590
authored
Jan 29, 2018
by
Oswaldo Ferreira
Committed by
Rémy Coutable
Jan 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close and do not reload MR diffs when source branch is deleted
parent
f195ac03
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+14
-2
changelogs/unreleased/osw-fix-lost-diffs-when-source-branch-deleted.yml
...eleased/osw-fix-lost-diffs-when-source-branch-deleted.yml
+5
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+1
-1
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+23
-2
No files found.
app/services/merge_requests/refresh_service.rb
View file @
df44c590
...
@@ -9,7 +9,8 @@ module MergeRequests
...
@@ -9,7 +9,8 @@ module MergeRequests
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
(
&
method
(
:find_new_commits
))
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
(
&
method
(
:find_new_commits
))
# Be sure to close outstanding MRs before reloading them to avoid generating an
# Be sure to close outstanding MRs before reloading them to avoid generating an
# empty diff during a manual merge
# empty diff during a manual merge
close_merge_requests
close_upon_missing_source_branch_ref
post_merge_manually_merged
reload_merge_requests
reload_merge_requests
reset_merge_when_pipeline_succeeds
reset_merge_when_pipeline_succeeds
mark_pending_todos_done
mark_pending_todos_done
...
@@ -29,11 +30,22 @@ module MergeRequests
...
@@ -29,11 +30,22 @@ module MergeRequests
private
private
def
close_upon_missing_source_branch_ref
# MergeRequest#reload_diff ignores not opened MRs. This means it won't
# create an `empty` diff for `closed` MRs without a source branch, keeping
# the latest diff state as the last _valid_ one.
merge_requests_for_source_branch
.
reject
(
&
:source_branch_exists?
).
each
do
|
mr
|
MergeRequests
::
CloseService
.
new
(
mr
.
target_project
,
@current_user
)
.
execute
(
mr
)
end
end
# Collect open merge requests that target same branch we push into
# Collect open merge requests that target same branch we push into
# and close if push to master include last commit from merge request
# and close if push to master include last commit from merge request
# We need this to close(as merged) merge requests that were merged into
# We need this to close(as merged) merge requests that were merged into
# target branch manually
# target branch manually
def
close_merge_requests
def
post_merge_manually_merged
commit_ids
=
@commits
.
map
(
&
:id
)
commit_ids
=
@commits
.
map
(
&
:id
)
merge_requests
=
@project
.
merge_requests
.
preload
(
:latest_merge_request_diff
).
opened
.
where
(
target_branch:
@branch_name
).
to_a
merge_requests
=
@project
.
merge_requests
.
preload
(
:latest_merge_request_diff
).
opened
.
where
(
target_branch:
@branch_name
).
to_a
merge_requests
=
merge_requests
.
select
(
&
:diff_head_commit
)
merge_requests
=
merge_requests
.
select
(
&
:diff_head_commit
)
...
...
changelogs/unreleased/osw-fix-lost-diffs-when-source-branch-deleted.yml
0 → 100644
View file @
df44c590
---
title
:
Close and do not reload MR diffs when source branch is deleted
merge_request
:
author
:
type
:
fixed
spec/models/merge_request_spec.rb
View file @
df44c590
...
@@ -1539,7 +1539,7 @@ describe MergeRequest do
...
@@ -1539,7 +1539,7 @@ describe MergeRequest do
expect
{
subject
.
reload_diff
}.
to
change
{
subject
.
merge_request_diffs
.
count
}.
by
(
1
)
expect
{
subject
.
reload_diff
}.
to
change
{
subject
.
merge_request_diffs
.
count
}.
by
(
1
)
end
end
it
"executs diff cache service"
do
it
"execut
e
s diff cache service"
do
expect_any_instance_of
(
MergeRequests
::
MergeRequestDiffCacheService
).
to
receive
(
:execute
).
with
(
subject
)
expect_any_instance_of
(
MergeRequests
::
MergeRequestDiffCacheService
).
to
receive
(
:execute
).
with
(
subject
)
subject
.
reload_diff
subject
.
reload_diff
...
...
spec/services/merge_requests/refresh_service_spec.rb
View file @
df44c590
...
@@ -55,11 +55,12 @@ describe MergeRequests::RefreshService do
...
@@ -55,11 +55,12 @@ describe MergeRequests::RefreshService do
before
do
before
do
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
end
it
'executes hooks with update action'
do
it
'executes hooks with update action'
do
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
expect
(
refresh_service
).
to
have_received
(
:execute_hooks
)
expect
(
refresh_service
).
to
have_received
(
:execute_hooks
)
.
with
(
@merge_request
,
'update'
,
old_rev:
@oldrev
)
.
with
(
@merge_request
,
'update'
,
old_rev:
@oldrev
)
...
@@ -72,6 +73,26 @@ describe MergeRequests::RefreshService do
...
@@ -72,6 +73,26 @@ describe MergeRequests::RefreshService do
expect
(
@build_failed_todo
).
to
be_done
expect
(
@build_failed_todo
).
to
be_done
expect
(
@fork_build_failed_todo
).
to
be_done
expect
(
@fork_build_failed_todo
).
to
be_done
end
end
context
'when source branch ref does not exists'
do
before
do
DeleteBranchService
.
new
(
@project
,
@user
).
execute
(
@merge_request
.
source_branch
)
end
it
'closes MRs without source branch ref'
do
expect
{
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
}
.
to
change
{
@merge_request
.
reload
.
state
}
.
from
(
'opened'
)
.
to
(
'closed'
)
expect
(
@fork_merge_request
.
reload
).
to
be_open
end
it
'does not change the merge request diff'
do
expect
{
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
}
.
not_to
change
{
@merge_request
.
reload
.
merge_request_diff
}
end
end
end
end
context
'when pipeline exists for the source branch'
do
context
'when pipeline exists for the source branch'
do
...
...
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