BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
223b87d7
Commit
223b87d7
authored
Jun 06, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport Fix '/unassign' slash command
parent
1d5e5f75
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
15 deletions
+27
-15
interpret_service.rb
app/services/slash_commands/interpret_service.rb
+15
-9
command_definition.rb
lib/gitlab/slash_commands/command_definition.rb
+8
-2
dsl.rb
lib/gitlab/slash_commands/dsl.rb
+2
-2
bulk_update_service_spec.rb
spec/services/issuable/bulk_update_service_spec.rb
+1
-1
interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+1
-1
No files found.
app/services/slash_commands/interpret_service.rb
View file @
223b87d7
...
@@ -92,26 +92,20 @@ module SlashCommands
...
@@ -92,26 +92,20 @@ module SlashCommands
desc
'Assign'
desc
'Assign'
explanation
do
|
users
|
explanation
do
|
users
|
"Assigns
#{
users
.
map
(
&
:to_reference
).
to_sent
ence
}
."
if
users
.
any?
"Assigns
#{
users
.
first
.
to_refer
ence
}
."
if
users
.
any?
end
end
params
'@user'
params
'@user'
condition
do
condition
do
current_user
.
can?
(
:"admin_
#{
issuable
.
to_ability_name
}
"
,
project
)
current_user
.
can?
(
:"admin_
#{
issuable
.
to_ability_name
}
"
,
project
)
end
end
parse_params
do
|
assignee_param
|
parse_params
do
|
assignee_param
|
users
=
extract_references
(
assignee_param
,
:user
)
extract_users
(
assignee_param
)
if
users
.
empty?
users
=
User
.
where
(
username:
assignee_param
.
split
(
' '
).
map
(
&
:strip
))
end
users
end
end
command
:assign
do
|
users
|
command
:assign
do
|
users
|
next
if
users
.
empty?
next
if
users
.
empty?
if
issuable
.
is_a?
(
Issue
)
if
issuable
.
is_a?
(
Issue
)
@updates
[
:assignee_ids
]
=
users
.
map
(
&
:id
)
@updates
[
:assignee_ids
]
=
[
users
.
last
.
id
]
else
else
@updates
[
:assignee_id
]
=
users
.
last
.
id
@updates
[
:assignee_id
]
=
users
.
last
.
id
end
end
...
@@ -459,6 +453,18 @@ module SlashCommands
...
@@ -459,6 +453,18 @@ module SlashCommands
end
end
end
end
def
extract_users
(
params
)
return
[]
if
params
.
nil?
users
=
extract_references
(
params
,
:user
)
if
users
.
empty?
users
=
User
.
where
(
username:
params
.
split
(
' '
).
map
(
&
:strip
))
end
users
end
def
find_labels
(
labels_param
)
def
find_labels
(
labels_param
)
extract_references
(
labels_param
,
:label
)
|
extract_references
(
labels_param
,
:label
)
|
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
,
name:
labels_param
.
split
).
execute
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
,
name:
labels_param
.
split
).
execute
...
...
lib/gitlab/slash_commands/command_definition.rb
View file @
223b87d7
...
@@ -48,17 +48,23 @@ module Gitlab
...
@@ -48,17 +48,23 @@ module Gitlab
end
end
def
to_h
(
opts
)
def
to_h
(
opts
)
context
=
OpenStruct
.
new
(
opts
)
desc
=
description
desc
=
description
if
desc
.
respond_to?
(
:call
)
if
desc
.
respond_to?
(
:call
)
context
=
OpenStruct
.
new
(
opts
)
desc
=
context
.
instance_exec
(
&
desc
)
rescue
''
desc
=
context
.
instance_exec
(
&
desc
)
rescue
''
end
end
prms
=
params
if
prms
.
respond_to?
(
:call
)
prms
=
Array
(
context
.
instance_exec
(
&
prms
))
rescue
params
end
{
{
name:
name
,
name:
name
,
aliases:
aliases
,
aliases:
aliases
,
description:
desc
,
description:
desc
,
params:
p
ara
ms
params:
p
r
ms
}
}
end
end
...
...
lib/gitlab/slash_commands/dsl.rb
View file @
223b87d7
...
@@ -40,8 +40,8 @@ module Gitlab
...
@@ -40,8 +40,8 @@ module Gitlab
# command :command_key do |arguments|
# command :command_key do |arguments|
# # Awesome code block
# # Awesome code block
# end
# end
def
params
(
*
params
)
def
params
(
*
params
,
&
block
)
@params
=
params
@params
=
block_given?
?
block
:
params
end
end
# Allows to give an explanation of what the command will do when
# Allows to give an explanation of what the command will do when
...
...
spec/services/issuable/bulk_update_service_spec.rb
View file @
223b87d7
...
@@ -72,7 +72,7 @@ describe Issuable::BulkUpdateService, services: true do
...
@@ -72,7 +72,7 @@ describe Issuable::BulkUpdateService, services: true do
end
end
context
"when the new assignee ID is
#{
IssuableFinder
::
NONE
}
"
do
context
"when the new assignee ID is
#{
IssuableFinder
::
NONE
}
"
do
it
"unassigns the issues"
do
it
'unassigns the issues'
do
expect
{
bulk_update
(
merge_request
,
assignee_id:
IssuableFinder
::
NONE
)
}
expect
{
bulk_update
(
merge_request
,
assignee_id:
IssuableFinder
::
NONE
)
}
.
to
change
{
merge_request
.
reload
.
assignee
}.
to
(
nil
)
.
to
change
{
merge_request
.
reload
.
assignee
}.
to
(
nil
)
end
end
...
...
spec/services/slash_commands/interpret_service_spec.rb
View file @
223b87d7
...
@@ -384,7 +384,7 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -384,7 +384,7 @@ describe SlashCommands::InterpretService, services: true do
it
'fetches assignee and populates assignee_id if content contains /assign'
do
it
'fetches assignee and populates assignee_id if content contains /assign'
do
_
,
updates
=
service
.
execute
(
content
,
issue
)
_
,
updates
=
service
.
execute
(
content
,
issue
)
expect
(
updates
[
:assignee_ids
]).
to
match_array
([
developer
.
id
,
developer2
.
id
])
expect
(
updates
[
:assignee_ids
]).
to
match_array
([
developer
.
id
])
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