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
ba6049c6
Commit
ba6049c6
authored
Oct 03, 2018
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EE-port Move issue related_branches to service
parent
98fee756
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
58 deletions
+66
-58
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-1
app/models/issue.rb
app/models/issue.rb
+0
-18
app/services/issues/related_branches_service.rb
app/services/issues/related_branches_service.rb
+26
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+0
-39
spec/services/issues/related_branches_service_spec.rb
spec/services/issues/related_branches_service_spec.rb
+39
-0
No files found.
app/controllers/projects/issues_controller.rb
View file @
ba6049c6
...
@@ -131,7 +131,7 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -131,7 +131,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
def
related_branches
def
related_branches
@related_branches
=
@issue
.
related_branches
(
current_user
)
@related_branches
=
Issues
::
RelatedBranchesService
.
new
(
project
,
current_user
).
execute
(
issue
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
do
format
.
json
do
...
...
app/models/issue.rb
View file @
ba6049c6
...
@@ -177,24 +177,6 @@ class Issue < ActiveRecord::Base
...
@@ -177,24 +177,6 @@ class Issue < ActiveRecord::Base
"
#{
project
.
to_reference
(
from
,
full:
full
)
}#{
reference
}
"
"
#{
project
.
to_reference
(
from
,
full:
full
)
}#{
reference
}
"
end
end
# All branches containing the current issue's ID, except for
# those with a merge request open referencing the current issue.
# rubocop: disable CodeReuse/ServiceClass
def
related_branches
(
current_user
)
branches_with_iid
=
project
.
repository
.
branch_names
.
select
do
|
branch
|
branch
=~
/\A
#{
iid
}
-(?!\d+-stable)/i
end
branches_with_merge_request
=
Issues
::
ReferencedMergeRequestsService
.
new
(
project
,
current_user
)
.
referenced_merge_requests
(
self
)
.
map
(
&
:source_branch
)
branches_with_iid
-
branches_with_merge_request
end
# rubocop: enable CodeReuse/ServiceClass
def
related_issues
(
current_user
,
preload:
nil
)
def
related_issues
(
current_user
,
preload:
nil
)
related_issues
=
Issue
related_issues
=
Issue
.
select
([
'issues.*'
,
'issue_links.id AS issue_link_id'
])
.
select
([
'issues.*'
,
'issue_links.id AS issue_link_id'
])
...
...
app/services/issues/related_branches_service.rb
0 → 100644
View file @
ba6049c6
# frozen_string_literal: true
# This service fetches all branches containing the current issue's ID, except for
# those with a merge request open referencing the current issue.
module
Issues
class
RelatedBranchesService
<
Issues
::
BaseService
def
execute
(
issue
)
branches_with_iid_of
(
issue
)
-
branches_with_merge_request_for
(
issue
)
end
private
def
branches_with_merge_request_for
(
issue
)
Issues
::
ReferencedMergeRequestsService
.
new
(
project
,
current_user
)
.
referenced_merge_requests
(
issue
)
.
map
(
&
:source_branch
)
end
def
branches_with_iid_of
(
issue
)
project
.
repository
.
branch_names
.
select
do
|
branch
|
branch
=~
/\A
#{
issue
.
iid
}
-(?!\d+-stable)/i
end
end
end
end
spec/models/issue_spec.rb
View file @
ba6049c6
...
@@ -268,45 +268,6 @@ describe Issue do
...
@@ -268,45 +268,6 @@ describe Issue do
end
end
end
end
describe
'#related_branches'
do
let
(
:user
)
{
create
(
:admin
)
}
before
do
allow
(
subject
.
project
.
repository
).
to
receive
(
:branch_names
)
.
and_return
([
"mpempe"
,
"
#{
subject
.
iid
}
mepmep"
,
subject
.
to_branch_name
,
"
#{
subject
.
iid
}
-branch"
])
# Without this stub, the `create(:merge_request)` above fails because it can't find
# the source branch. This seems like a reasonable compromise, in comparison with
# setting up a full repo here.
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:create_merge_request_diff
)
end
it
"selects the right branches when there are no referenced merge requests"
do
expect
(
subject
.
related_branches
(
user
)).
to
eq
([
subject
.
to_branch_name
,
"
#{
subject
.
iid
}
-branch"
])
end
it
"selects the right branches when there is a referenced merge request"
do
merge_request
=
create
(
:merge_request
,
{
description:
"Closes #
#{
subject
.
iid
}
"
,
source_project:
subject
.
project
,
source_branch:
"
#{
subject
.
iid
}
-branch"
})
merge_request
.
create_cross_references!
(
user
)
referenced_merge_requests
=
Issues
::
ReferencedMergeRequestsService
.
new
(
subject
.
project
,
user
)
.
referenced_merge_requests
(
subject
)
expect
(
referenced_merge_requests
).
not_to
be_empty
expect
(
subject
.
related_branches
(
user
)).
to
eq
([
subject
.
to_branch_name
])
end
it
'excludes stable branches from the related branches'
do
allow
(
subject
.
project
.
repository
).
to
receive
(
:branch_names
)
.
and_return
([
"
#{
subject
.
iid
}
-0-stable"
])
expect
(
subject
.
related_branches
(
user
)).
to
eq
[]
end
end
describe
'#related_issues'
do
describe
'#related_issues'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:authorized_project
)
{
create
(
:project
)
}
let
(
:authorized_project
)
{
create
(
:project
)
}
...
...
spec/services/issues/related_branches_service_spec.rb
0 → 100644
View file @
ba6049c6
require
'spec_helper'
describe
Issues
::
RelatedBranchesService
do
let
(
:user
)
{
create
(
:admin
)
}
let
(
:issue
)
{
create
(
:issue
)
}
subject
{
described_class
.
new
(
issue
.
project
,
user
)
}
describe
'#execute'
do
before
do
allow
(
issue
.
project
.
repository
).
to
receive
(
:branch_names
).
and_return
([
"mpempe"
,
"
#{
issue
.
iid
}
mepmep"
,
issue
.
to_branch_name
,
"
#{
issue
.
iid
}
-branch"
])
end
it
"selects the right branches when there are no referenced merge requests"
do
expect
(
subject
.
execute
(
issue
)).
to
eq
([
issue
.
to_branch_name
,
"
#{
issue
.
iid
}
-branch"
])
end
it
"selects the right branches when there is a referenced merge request"
do
merge_request
=
create
(
:merge_request
,
{
description:
"Closes #
#{
issue
.
iid
}
"
,
source_project:
issue
.
project
,
source_branch:
"
#{
issue
.
iid
}
-branch"
})
merge_request
.
create_cross_references!
(
user
)
referenced_merge_requests
=
Issues
::
ReferencedMergeRequestsService
.
new
(
issue
.
project
,
user
)
.
referenced_merge_requests
(
issue
)
expect
(
referenced_merge_requests
).
not_to
be_empty
expect
(
subject
.
execute
(
issue
)).
to
eq
([
issue
.
to_branch_name
])
end
it
'excludes stable branches from the related branches'
do
allow
(
issue
.
project
.
repository
).
to
receive
(
:branch_names
)
.
and_return
([
"
#{
issue
.
iid
}
-0-stable"
])
expect
(
subject
.
execute
(
issue
)).
to
eq
[]
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