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
9727255a
Commit
9727255a
authored
Jun 22, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Groups::AutocompleteService#labels
parent
a3cfd4b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
30 deletions
+29
-30
ee/app/controllers/groups/autocomplete_sources_controller.rb
ee/app/controllers/groups/autocomplete_sources_controller.rb
+1
-1
ee/app/services/groups/autocomplete_service.rb
ee/app/services/groups/autocomplete_service.rb
+13
-13
ee/spec/services/groups/autocomplete_service_spec.rb
ee/spec/services/groups/autocomplete_service_spec.rb
+15
-16
No files found.
ee/app/controllers/groups/autocomplete_sources_controller.rb
View file @
9727255a
...
...
@@ -6,7 +6,7 @@ class Groups::AutocompleteSourcesController < Groups::ApplicationController
end
def
labels
render
json:
@autocomplete_service
.
labels
(
target
)
render
json:
@autocomplete_service
.
labels
_as_hash
(
target
)
end
def
epics
...
...
ee/app/services/groups/autocomplete_service.rb
View file @
9727255a
module
Groups
class
AutocompleteService
<
Groups
::
BaseService
def
labels
(
target
=
nil
)
labels
=
LabelsFinder
.
new
(
def
labels
_as_hash
(
target
=
nil
)
available_
labels
=
LabelsFinder
.
new
(
current_user
,
group_id:
group
.
id
,
include_ancestor_groups:
true
,
only_group_labels:
true
).
execute
.
select
([
:color
,
:title
])
).
execute
return
labels
unless
target
&
.
respond_to?
(
:labels
)
hashes
=
available_labels
.
as_json
(
only:
[
:title
,
:color
]
)
i
ssuable_label_titles
=
target
.
labels
.
pluck
(
:title
)
if
issuable_label_titles
labels
=
labels
.
as_json
(
only:
[
:title
,
:color
])
issuable_label_titles
.
each
do
|
issuable_label_title
|
found_label
=
labels
.
find
{
|
label
|
label
[
'title'
]
==
issuable_label_title
}
found_label
[
:set
]
=
true
if
found_label
i
f
target
&
.
respond_to?
(
:labels
)
if
already_set_labels
=
available_labels
&
target
.
labels
titles
=
already_set_labels
.
map
(
&
:title
)
hashes
.
each
do
|
hash
|
if
titles
.
include?
(
hash
[
'title'
])
hash
[
:set
]
=
true
end
end
end
end
label
s
hashe
s
end
def
epics
...
...
ee/spec/services/groups/autocomplete_service_spec.rb
View file @
9727255a
...
...
@@ -10,12 +10,10 @@ describe Groups::AutocompleteService do
create
(
:group_member
,
group:
group
,
user:
user
)
end
def
user_to_autocompletable
(
user
)
{
username:
user
.
username
,
name:
user
.
name
,
avatar_url:
user
.
avatar_url
}
def
expect_labels_to_equal
(
labels
,
expected_labels
)
expect
(
labels
.
size
).
to
eq
(
expected_labels
.
size
)
extract_title
=
lambda
{
|
label
|
label
[
'title'
]
}
expect
(
labels
.
map
(
&
extract_title
)).
to
eq
(
expected_labels
.
map
(
&
extract_title
))
end
describe
'#labels'
do
...
...
@@ -26,12 +24,10 @@ describe Groups::AutocompleteService do
it
'returns labels from own group and ancestor groups'
do
service
=
described_class
.
new
(
group
,
user
)
result
=
service
.
labels
results
=
service
.
labels_as_hash
expected_labels
=
[
label1
,
label2
,
parent_group_label
]
expect
(
result
.
size
).
to
eq
(
3
)
expect
(
result
.
map
(
&
:title
)).
to
contain_exactly
(
*
expected_labels
.
map
(
&
:title
))
expect_labels_to_equal
(
results
,
expected_labels
)
end
context
'some labels are already assigned'
do
...
...
@@ -41,15 +37,18 @@ describe Groups::AutocompleteService do
it
'marks already assigned as set'
do
service
=
described_class
.
new
(
group
,
user
)
result
=
service
.
labels
(
epic
)
results
=
service
.
labels_as_hash
(
epic
)
expected_labels
=
[
label1
,
label2
,
parent_group_label
]
expect
(
result
.
size
).
to
eq
(
3
)
expect
(
result
.
map
{
|
label
|
label
[
'title'
]
}).
to
contain_exactly
(
*
expected_labels
.
map
(
&
:title
))
expect_labels_to_equal
(
results
,
expected_labels
)
epic
.
labels
.
each
do
|
assigned_label
|
expect
(
result
.
find
{
|
label
|
label
[
'title'
]
==
assigned_label
.
title
}[
:set
]).
to
eq
(
true
)
assigned_label_titles
=
epic
.
labels
.
map
(
&
:title
)
results
.
each
do
|
hash
|
if
assigned_label_titles
.
include?
(
hash
[
'title'
])
expect
(
hash
[
:set
]).
to
eq
(
true
)
else
expect
(
hash
.
key?
(
:set
)).
to
eq
(
false
)
end
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