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
92a5becc
Commit
92a5becc
authored
Jun 16, 2021
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '201745-add-from-fork-scope' into 'master'
Add from_fork scope See merge request gitlab-org/gitlab!64177
parents
a2a6cbb5
6aa839eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
6 deletions
+18
-6
app/models/merge_request.rb
app/models/merge_request.rb
+2
-1
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+5
-5
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+11
-0
No files found.
app/models/merge_request.rb
View file @
92a5becc
...
...
@@ -263,8 +263,9 @@ class MergeRequest < ApplicationRecord
scope
:by_milestone
,
->
(
milestone
)
{
where
(
milestone_id:
milestone
)
}
scope
:of_projects
,
->
(
ids
)
{
where
(
target_project_id:
ids
)
}
scope
:from_project
,
->
(
project
)
{
where
(
source_project_id:
project
.
id
)
}
scope
:from_fork
,
->
{
where
(
'source_project_id <> target_project_id'
)
}
scope
:from_and_to_forks
,
->
(
project
)
do
where
(
'source_project_id <> target_project_id AND (source_project_id = ? OR target_project_id = ?)
'
,
project
.
id
,
project
.
id
)
from_fork
.
where
(
'source_project_id = ? OR target_project_id = ?
'
,
project
.
id
,
project
.
id
)
end
scope
:merged
,
->
{
with_state
(
:merged
)
}
scope
:closed_and_merged
,
->
{
with_states
(
:closed
,
:merged
)
}
...
...
app/services/merge_requests/refresh_service.rb
View file @
92a5becc
...
...
@@ -294,14 +294,14 @@ module MergeRequests
@source_merge_requests
||=
merge_requests_for
(
@push
.
branch_name
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
merge_requests_for_forks
@merge_requests_for_forks
||=
MergeRequest
.
opened
.
where
(
source_branch:
@push
.
branch_name
,
source_project:
@project
)
.
where
.
not
(
target_project:
@project
)
MergeRequest
.
opened
.
from_project
(
project
)
.
from_source_branches
(
@push
.
branch_name
)
.
from_fork
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
...
...
spec/models/merge_request_spec.rb
View file @
92a5becc
...
...
@@ -4951,4 +4951,15 @@ RSpec.describe MergeRequest, factory_default: :keep do
it
{
is_expected
.
to
eq
(
true
)
}
end
end
describe
'.from_fork'
do
let!
(
:project
)
{
create
(
:project
,
:repository
)
}
let!
(
:forked_project
)
{
fork_project
(
project
)
}
let!
(
:fork_mr
)
{
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
project
)
}
let!
(
:regular_mr
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
'returns merge requests from forks only'
do
expect
(
described_class
.
from_fork
).
to
eq
([
fork_mr
])
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