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
31af7e87
Commit
31af7e87
authored
Feb 21, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'weight-slash-command' into 'master'
Added weight slash command Closes #852 See merge request !1255
parents
becf6e4c
7c831be0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
0 deletions
+140
-0
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+23
-0
changelogs/unreleased-ee/weight-slash-command.yml
changelogs/unreleased-ee/weight-slash-command.yml
+4
-0
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 @
31af7e87
...
...
@@ -316,6 +316,29 @@ module SlashCommands
@updates
[
:target_branch
]
=
branch_name
if
project
.
repository
.
branch_names
.
include?
(
branch_name
)
end
desc
'Set weight'
params
Issue
::
WEIGHT_RANGE
.
to_s
.
squeeze
(
'.'
).
tr
(
'.'
,
'-'
)
condition
do
issuable
.
respond_to?
(
:weight
)
&&
current_user
.
can?
(
:"admin_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
end
command
:weight
do
|
weight
|
if
Issue
.
weight_filter_options
.
include?
(
weight
.
to_i
)
@updates
[
:weight
]
=
weight
.
to_i
end
end
desc
'Clear weight'
condition
do
issuable
.
persisted?
&&
issuable
.
respond_to?
(
:weight
)
&&
issuable
.
weight?
&&
current_user
.
can?
(
:"admin_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
end
command
:clear_weight
do
@updates
[
:weight
]
=
nil
end
def
find_label_ids
(
labels_param
)
label_ids_by_reference
=
extract_references
(
labels_param
,
:label
).
map
(
&
:id
)
labels_ids_by_name
=
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
,
name:
labels_param
.
split
).
execute
.
select
(
:id
)
...
...
changelogs/unreleased-ee/weight-slash-command.yml
0 → 100644
View file @
31af7e87
---
title
:
Added weight slash command
merge_request
:
author
:
doc/user/project/slash_commands.md
View file @
31af7e87
...
...
@@ -35,3 +35,5 @@ do.
|
<code>
/spend
<
1h 30m
|
-1h 5m
>
</code>
| Add or subtract spent time |
|
`/remove_time_spent`
| Remove time spent |
|
`/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 @
31af7e87
...
...
@@ -161,5 +161,81 @@ feature 'Issues > User uses slash commands', feature: true, js: true do
expect
(
page
).
not_to
have_content
'/wip'
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
spec/features/merge_requests/user_uses_slash_commands_spec.rb
View file @
31af7e87
...
...
@@ -196,5 +196,13 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do
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
spec/services/slash_commands/interpret_service_spec.rb
View file @
31af7e87
...
...
@@ -267,6 +267,23 @@ describe SlashCommands::InterpretService, services: true do
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
let
(
:content
)
{
'/reopen'
}
let
(
:issuable
)
{
issue
}
...
...
@@ -603,6 +620,16 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
issue
}
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
let
(
:visitor
)
{
create
(
:user
)
}
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