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
8213fc6a
Commit
8213fc6a
authored
Oct 10, 2016
by
barthc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow multiple labels commands
parent
960cd184
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
3 deletions
+62
-3
CHANGELOG
CHANGELOG
+1
-0
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+18
-3
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+43
-0
No files found.
CHANGELOG
View file @
8213fc6a
...
@@ -91,6 +91,7 @@ v 8.13.0 (unreleased)
...
@@ -91,6 +91,7 @@ v 8.13.0 (unreleased)
- Close todos when accepting merge requests via the API !6486 (tonygambone)
- Close todos when accepting merge requests via the API !6486 (tonygambone)
- Changed Slack service user referencing from full name to username (Sebastian Poxhofer)
- Changed Slack service user referencing from full name to username (Sebastian Poxhofer)
- Retouch environments list and deployments list
- Retouch environments list and deployments list
- Add multiple command support for all label related slash commands !6780 (barthc)
- Add Container Registry on/off status to Admin Area !6638 (the-undefined)
- Add Container Registry on/off status to Admin Area !6638 (the-undefined)
- Allow empty merge requests !6384 (Artem Sidorenko)
- Allow empty merge requests !6384 (Artem Sidorenko)
- Grouped pipeline dropdown is a scrollable container
- Grouped pipeline dropdown is a scrollable container
...
...
app/services/slash_commands/interpret_service.rb
View file @
8213fc6a
...
@@ -122,7 +122,12 @@ module SlashCommands
...
@@ -122,7 +122,12 @@ module SlashCommands
command
:label
do
|
labels_param
|
command
:label
do
|
labels_param
|
label_ids
=
find_label_ids
(
labels_param
)
label_ids
=
find_label_ids
(
labels_param
)
@updates
[
:add_label_ids
]
=
label_ids
unless
label_ids
.
empty?
if
label_ids
.
any?
@updates
[
:add_label_ids
]
||=
[]
@updates
[
:add_label_ids
]
+=
label_ids
@updates
[
:add_label_ids
].
uniq!
end
end
end
desc
'Remove all or specific label(s)'
desc
'Remove all or specific label(s)'
...
@@ -136,7 +141,12 @@ module SlashCommands
...
@@ -136,7 +141,12 @@ module SlashCommands
if
labels_param
.
present?
if
labels_param
.
present?
label_ids
=
find_label_ids
(
labels_param
)
label_ids
=
find_label_ids
(
labels_param
)
@updates
[
:remove_label_ids
]
=
label_ids
unless
label_ids
.
empty?
if
label_ids
.
any?
@updates
[
:remove_label_ids
]
||=
[]
@updates
[
:remove_label_ids
]
+=
label_ids
@updates
[
:remove_label_ids
].
uniq!
end
else
else
@updates
[
:label_ids
]
=
[]
@updates
[
:label_ids
]
=
[]
end
end
...
@@ -152,7 +162,12 @@ module SlashCommands
...
@@ -152,7 +162,12 @@ module SlashCommands
command
:relabel
do
|
labels_param
|
command
:relabel
do
|
labels_param
|
label_ids
=
find_label_ids
(
labels_param
)
label_ids
=
find_label_ids
(
labels_param
)
@updates
[
:label_ids
]
=
label_ids
unless
label_ids
.
empty?
if
label_ids
.
any?
@updates
[
:label_ids
]
||=
[]
@updates
[
:label_ids
]
+=
label_ids
@updates
[
:label_ids
].
uniq!
end
end
end
desc
'Add a todo'
desc
'Add a todo'
...
...
spec/services/slash_commands/interpret_service_spec.rb
View file @
8213fc6a
...
@@ -86,6 +86,25 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -86,6 +86,25 @@ describe SlashCommands::InterpretService, services: true do
end
end
end
end
shared_examples
'multiple label command'
do
it
'fetches label ids and populates add_label_ids if content contains multiple /label'
do
bug
# populate the label
inprogress
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
add_label_ids:
[
inprogress
.
id
,
bug
.
id
])
end
end
shared_examples
'multiple label with same argument'
do
it
'prevents duplicate label ids and populates add_label_ids if content contains multiple /label'
do
inprogress
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
add_label_ids:
[
inprogress
.
id
])
end
end
shared_examples
'unlabel command'
do
shared_examples
'unlabel command'
do
it
'fetches label ids and populates remove_label_ids if content contains /unlabel'
do
it
'fetches label ids and populates remove_label_ids if content contains /unlabel'
do
issuable
.
update
(
label_ids:
[
inprogress
.
id
])
# populate the label
issuable
.
update
(
label_ids:
[
inprogress
.
id
])
# populate the label
...
@@ -95,6 +114,15 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -95,6 +114,15 @@ describe SlashCommands::InterpretService, services: true do
end
end
end
end
shared_examples
'multiple unlabel command'
do
it
'fetches label ids and populates remove_label_ids if content contains mutiple /unlabel'
do
issuable
.
update
(
label_ids:
[
inprogress
.
id
,
bug
.
id
])
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
remove_label_ids:
[
inprogress
.
id
,
bug
.
id
])
end
end
shared_examples
'unlabel command with no argument'
do
shared_examples
'unlabel command with no argument'
do
it
'populates label_ids: [] if content contains /unlabel with no arguments'
do
it
'populates label_ids: [] if content contains /unlabel with no arguments'
do
issuable
.
update
(
label_ids:
[
inprogress
.
id
])
# populate the label
issuable
.
update
(
label_ids:
[
inprogress
.
id
])
# populate the label
...
@@ -285,6 +313,16 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -285,6 +313,16 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
merge_request
}
let
(
:issuable
)
{
merge_request
}
end
end
it_behaves_like
'multiple label command'
do
let
(
:content
)
{
%(/label ~"#{inprogress.title}" \n/label ~#{bug.title})
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'multiple label with same argument'
do
let
(
:content
)
{
%(/label ~"#{inprogress.title}" \n/label ~#{inprogress.title})
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'unlabel command'
do
it_behaves_like
'unlabel command'
do
let
(
:content
)
{
%(/unlabel ~"#{inprogress.title}")
}
let
(
:content
)
{
%(/unlabel ~"#{inprogress.title}")
}
let
(
:issuable
)
{
issue
}
let
(
:issuable
)
{
issue
}
...
@@ -295,6 +333,11 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -295,6 +333,11 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
merge_request
}
let
(
:issuable
)
{
merge_request
}
end
end
it_behaves_like
'multiple unlabel command'
do
let
(
:content
)
{
%(/unlabel ~"#{inprogress.title}" \n/unlabel ~#{bug.title})
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'unlabel command with no argument'
do
it_behaves_like
'unlabel command with no argument'
do
let
(
:content
)
{
%(/unlabel)
}
let
(
:content
)
{
%(/unlabel)
}
let
(
:issuable
)
{
issue
}
let
(
:issuable
)
{
issue
}
...
...
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