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
4eb39e43
Commit
4eb39e43
authored
7 years ago
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport EE changes on approvals reset for closed MRs
parent
4b999ccd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
39 deletions
+52
-39
app/models/project.rb
app/models/project.rb
+0
-2
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+7
-9
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+8
-14
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+37
-14
No files found.
app/models/project.rb
View file @
4eb39e43
...
@@ -121,8 +121,6 @@ class Project < ActiveRecord::Base
...
@@ -121,8 +121,6 @@ class Project < ActiveRecord::Base
# Merge Requests for target project should be removed with it
# Merge Requests for target project should be removed with it
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
'target_project_id'
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
'target_project_id'
# Merge requests from source project should be kept when source project was removed
has_many
:fork_merge_requests
,
foreign_key:
'source_project_id'
,
class_name:
'MergeRequest'
has_many
:issues
,
dependent: :destroy
has_many
:issues
,
dependent: :destroy
has_many
:labels
,
dependent: :destroy
,
class_name:
'ProjectLabel'
has_many
:labels
,
dependent: :destroy
,
class_name:
'ProjectLabel'
has_many
:services
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
...
...
This diff is collapsed.
Click to expand it.
app/services/merge_requests/base_service.rb
View file @
4eb39e43
...
@@ -38,15 +38,13 @@ module MergeRequests
...
@@ -38,15 +38,13 @@ module MergeRequests
private
private
def
merge_requests_for
(
branch
)
# Returns all origin and fork merge requests from `@project` satisfying passed arguments.
origin_merge_requests
=
@project
.
origin_merge_requests
def
merge_requests_for
(
source_branch
,
mr_states:
[
:opened
])
.
opened
.
where
(
source_branch:
branch
).
to_a
MergeRequest
.
with_state
(
mr_states
)
fork_merge_requests
=
@project
.
fork_merge_requests
.
where
(
source_branch:
source_branch
,
source_project_id:
@project
.
id
)
.
opened
.
where
(
source_branch:
branch
).
to_a
.
preload
(
:source_project
)
# we don't need a #includes since we're just preloading for the #select
.
select
(
&
:source_project
)
(
origin_merge_requests
+
fork_merge_requests
)
.
uniq
.
select
(
&
:source_project
)
end
end
def
pipeline_merge_requests
(
pipeline
)
def
pipeline_merge_requests
(
pipeline
)
...
...
This diff is collapsed.
Click to expand it.
app/services/merge_requests/refresh_service.rb
View file @
4eb39e43
...
@@ -42,7 +42,7 @@ module MergeRequests
...
@@ -42,7 +42,7 @@ module MergeRequests
commit_ids
.
include?
(
merge_request
.
diff_head_sha
)
commit_ids
.
include?
(
merge_request
.
diff_head_sha
)
end
end
merge_requests
.
uniq
.
select
(
&
:source_project
).
each
do
|
merge_request
|
filter_merge_requests
(
merge_requests
).
each
do
|
merge_request
|
MergeRequests
::
PostMergeService
.
MergeRequests
::
PostMergeService
.
new
(
merge_request
.
target_project
,
@current_user
).
new
(
merge_request
.
target_project
,
@current_user
).
execute
(
merge_request
)
execute
(
merge_request
)
...
@@ -58,10 +58,13 @@ module MergeRequests
...
@@ -58,10 +58,13 @@ module MergeRequests
def
reload_merge_requests
def
reload_merge_requests
merge_requests
=
@project
.
merge_requests
.
opened
.
merge_requests
=
@project
.
merge_requests
.
opened
.
by_source_or_target_branch
(
@branch_name
).
to_a
by_source_or_target_branch
(
@branch_name
).
to_a
merge_requests
+=
fork_merge_requests
merge_requests
=
filter_merge_requests
(
merge_requests
)
merge_requests
.
each
do
|
merge_request
|
# Fork merge requests
merge_requests
+=
MergeRequest
.
opened
.
where
(
source_branch:
@branch_name
,
source_project:
@project
)
.
where
.
not
(
target_project:
@project
).
to_a
filter_merge_requests
(
merge_requests
).
each
do
|
merge_request
|
if
merge_request
.
source_branch
==
@branch_name
||
force_push?
if
merge_request
.
source_branch
==
@branch_name
||
force_push?
merge_request
.
reload_diff
merge_request
.
reload_diff
else
else
...
@@ -175,16 +178,7 @@ module MergeRequests
...
@@ -175,16 +178,7 @@ module MergeRequests
end
end
def
merge_requests_for_source_branch
def
merge_requests_for_source_branch
@source_merge_requests
||=
begin
@source_merge_requests
||=
merge_requests_for
(
@branch_name
)
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
@branch_name
).
to_a
merge_requests
+=
fork_merge_requests
filter_merge_requests
(
merge_requests
)
end
end
def
fork_merge_requests
@fork_merge_requests
||=
@project
.
fork_merge_requests
.
opened
.
where
(
source_branch:
@branch_name
).
to_a
end
end
def
branch_added?
def
branch_added?
...
...
This diff is collapsed.
Click to expand it.
spec/services/merge_requests/refresh_service_spec.rb
View file @
4eb39e43
...
@@ -106,23 +106,46 @@ describe MergeRequests::RefreshService, services: true do
...
@@ -106,23 +106,46 @@ describe MergeRequests::RefreshService, services: true do
context
'push to fork repo source branch'
do
context
'push to fork repo source branch'
do
let
(
:refresh_service
)
{
service
.
new
(
@fork_project
,
@user
)
}
let
(
:refresh_service
)
{
service
.
new
(
@fork_project
,
@user
)
}
before
do
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'executes hooks with update action'
do
context
'open fork merge request'
do
expect
(
refresh_service
).
to
have_received
(
:execute_hooks
).
before
do
with
(
@fork_merge_request
,
'update'
,
@oldrev
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'executes hooks with update action'
do
expect
(
refresh_service
).
to
have_received
(
:execute_hooks
).
with
(
@fork_merge_request
,
'update'
,
@oldrev
)
end
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
(
'added 28 commits'
)
}
it
{
expect
(
@fork_merge_request
).
to
be_open
}
it
{
expect
(
@build_failed_todo
).
to
be_pending
}
it
{
expect
(
@fork_build_failed_todo
).
to
be_pending
}
end
end
it
{
expect
(
@merge_request
.
notes
).
to
be_empty
}
context
'closed fork merge request'
do
it
{
expect
(
@merge_request
).
to
be_open
}
before
do
it
{
expect
(
@fork_merge_request
.
notes
.
last
.
note
).
to
include
(
'added 28 commits'
)
}
@fork_merge_request
.
close!
it
{
expect
(
@fork_merge_request
).
to
be_open
}
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
it
{
expect
(
@build_failed_todo
).
to
be_pending
}
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
it
{
expect
(
@fork_build_failed_todo
).
to
be_pending
}
reload_mrs
end
it
'do not execute hooks with update action'
do
expect
(
refresh_service
).
not_to
have_received
(
:execute_hooks
)
end
it
{
expect
(
@merge_request
.
notes
).
to
be_empty
}
it
{
expect
(
@merge_request
).
to
be_open
}
it
{
expect
(
@fork_merge_request
.
notes
).
to
be_empty
}
it
{
expect
(
@fork_merge_request
).
to
be_closed
}
it
{
expect
(
@build_failed_todo
).
to
be_pending
}
it
{
expect
(
@fork_build_failed_todo
).
to
be_pending
}
end
end
end
context
'push to fork repo target branch'
do
context
'push to fork repo target branch'
do
...
...
This diff is collapsed.
Click to expand it.
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