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
db7ee8ae
Commit
db7ee8ae
authored
Feb 17, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests
Updated docs
parent
476d146e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
3 deletions
+115
-3
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+2
-3
doc/user/project/slash_commands.md
doc/user/project/slash_commands.md
+2
-0
spec/features/issues/user_uses_slash_commands_spec.rb
spec/features/issues/user_uses_slash_commands_spec.rb
+76
-0
spec/features/merge_requests/user_uses_slash_commands_spec.rb
.../features/merge_requests/user_uses_slash_commands_spec.rb
+8
-0
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+27
-0
No files found.
app/services/slash_commands/interpret_service.rb
View file @
db7ee8ae
...
@@ -319,13 +319,12 @@ module SlashCommands
...
@@ -319,13 +319,12 @@ module SlashCommands
desc
'Set weight'
desc
'Set weight'
params
'1-9'
params
'1-9'
condition
do
condition
do
issuable
.
persisted?
&&
issuable
.
is_a?
(
Issue
)
&&
issuable
.
is_a?
(
Issue
)
&&
current_user
.
can?
(
:"update_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
current_user
.
can?
(
:"update_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
end
end
command
:weight
do
|
weight
|
command
:weight
do
|
weight
|
if
Issue
.
weight_filter_options
.
include?
(
weight
.
to_i
)
if
Issue
.
weight_filter_options
.
include?
(
weight
.
to_i
)
@updates
[
:weight
]
=
weight
@updates
[
:weight
]
=
weight
.
to_i
end
end
end
end
...
...
doc/user/project/slash_commands.md
View file @
db7ee8ae
...
@@ -35,3 +35,5 @@ do.
...
@@ -35,3 +35,5 @@ do.
|
<code>
/spend
<
1h 30m
|
-1h 5m
>
</code>
| Add or subtract spent time |
|
<code>
/spend
<
1h 30m
|
-1h 5m
>
</code>
| Add or subtract spent time |
|
`/remove_time_spent`
| Remove time spent |
|
`/remove_time_spent`
| Remove time spent |
|
`/target_branch <Branch Name>`
| Set target branch for current merge request |
|
`/target_branch <Branch Name>`
| Set target branch for current merge request |
|
`/weight <1-9>`
| Set the weight of the issue |
|
`/clear_weight`
| Clears the issue weight |
spec/features/issues/user_uses_slash_commands_spec.rb
View file @
db7ee8ae
...
@@ -161,5 +161,81 @@ feature 'Issues > User uses slash commands', feature: true, js: true do
...
@@ -161,5 +161,81 @@ feature 'Issues > User uses slash commands', feature: true, js: true do
expect
(
page
).
not_to
have_content
'/wip'
expect
(
page
).
not_to
have_content
'/wip'
end
end
end
end
describe
'adding a weight from a note'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
context
'when the user can update the weight'
do
it
'does not create a note, and sets the weight accordingly'
do
write_note
(
"/weight 5"
)
expect
(
page
).
not_to
have_content
'/weight 5'
expect
(
page
).
to
have_content
'Commands applied'
issue
.
reload
expect
(
issue
.
weight
).
to
eq
(
5
)
end
end
context
'when the current user cannot update the weight'
do
let
(
:guest
)
{
create
(
:user
)
}
before
do
project
.
team
<<
[
guest
,
:guest
]
logout
login_with
(
guest
)
visit
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
)
end
it
'creates a note, and does not set the weight'
do
write_note
(
"/weight 5"
)
expect
(
page
).
to
have_content
'/weight 5'
expect
(
page
).
not_to
have_content
'Commands applied'
issue
.
reload
expect
(
issue
.
weight
).
not_to
eq
(
5
)
end
end
end
describe
'removing weight from a note'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
weight:
1
)
}
context
'when the user can update the weight'
do
it
'does not create a note, and removes the weight accordingly'
do
write_note
(
"/clear_weight"
)
expect
(
page
).
not_to
have_content
'/clear_weight'
expect
(
page
).
to
have_content
'Commands applied'
issue
.
reload
expect
(
issue
.
weight
).
to
eq
(
nil
)
end
end
context
'when the current user cannot update the weight'
do
let
(
:guest
)
{
create
(
:user
)
}
before
do
project
.
team
<<
[
guest
,
:guest
]
logout
login_with
(
guest
)
visit
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
)
end
it
'creates a note, and does not set the weight'
do
write_note
(
"/clear_weight"
)
expect
(
page
).
to
have_content
'/clear_weight'
expect
(
page
).
not_to
have_content
'Commands applied'
issue
.
reload
expect
(
issue
.
weight
).
to
eq
(
1
)
end
end
end
end
end
end
end
spec/features/merge_requests/user_uses_slash_commands_spec.rb
View file @
db7ee8ae
...
@@ -196,5 +196,13 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do
...
@@ -196,5 +196,13 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do
end
end
end
end
end
end
describe
'adding a weight from a note'
do
it
'does not recognize the command nor create a note'
do
write_note
(
"/weight 5"
)
expect
(
page
).
not_to
have_content
'/weight 5'
end
end
end
end
end
end
spec/services/slash_commands/interpret_service_spec.rb
View file @
db7ee8ae
...
@@ -267,6 +267,23 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -267,6 +267,23 @@ describe SlashCommands::InterpretService, services: true do
end
end
end
end
shared_examples
'weight command'
do
it
'populates weight: 5 if content contains /weight 5'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
weight:
5
)
end
end
shared_examples
'clear weight command'
do
it
'populates weight: nil if content contains /clear_weight'
do
issuable
.
update
(
weight:
5
)
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
weight:
nil
)
end
end
it_behaves_like
'reopen command'
do
it_behaves_like
'reopen command'
do
let
(
:content
)
{
'/reopen'
}
let
(
:content
)
{
'/reopen'
}
let
(
:issuable
)
{
issue
}
let
(
:issuable
)
{
issue
}
...
@@ -603,6 +620,16 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -603,6 +620,16 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
issue
}
let
(
:issuable
)
{
issue
}
end
end
it_behaves_like
'weight command'
do
let
(
:content
)
{
'/weight 5'
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'clear weight command'
do
let
(
:content
)
{
'/clear_weight'
}
let
(
:issuable
)
{
issue
}
end
context
'when current_user cannot :admin_issue'
do
context
'when current_user cannot :admin_issue'
do
let
(
:visitor
)
{
create
(
:user
)
}
let
(
:visitor
)
{
create
(
:user
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
visitor
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
visitor
)
}
...
...
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