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
Jérome Perrin
gitlab-ce
Commits
39f7f63f
Commit
39f7f63f
authored
Aug 09, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the /title slash command
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
7cc4ab14
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
12 deletions
+89
-12
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+1
-1
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+6
-0
doc/workflow/slash_commands.md
doc/workflow/slash_commands.md
+2
-1
spec/lib/gitlab/email/handler/create_note_handler_spec.rb
spec/lib/gitlab/email/handler/create_note_handler_spec.rb
+13
-2
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+30
-8
spec/support/issuable_slash_commands_shared_examples.rb
spec/support/issuable_slash_commands_shared_examples.rb
+37
-0
No files found.
app/services/issuable_base_service.rb
View file @
39f7f63f
...
@@ -86,7 +86,7 @@ class IssuableBaseService < BaseService
...
@@ -86,7 +86,7 @@ class IssuableBaseService < BaseService
remove_label_ids
=
attributes
.
delete
(
:remove_label_ids
)
remove_label_ids
=
attributes
.
delete
(
:remove_label_ids
)
new_label_ids
=
base_label_ids
new_label_ids
=
base_label_ids
new_label_ids
=
label_ids
if
label_ids
&&
(
merge_all
||
(
add_label_ids
.
empty?
&&
remove_label_ids
.
empty
?
))
new_label_ids
=
label_ids
if
label_ids
&&
(
merge_all
||
(
add_label_ids
.
blank?
&&
remove_label_ids
.
blank
?
))
new_label_ids
|=
add_label_ids
if
add_label_ids
new_label_ids
|=
add_label_ids
if
add_label_ids
new_label_ids
-=
remove_label_ids
if
remove_label_ids
new_label_ids
-=
remove_label_ids
if
remove_label_ids
...
...
app/services/slash_commands/interpret_service.rb
View file @
39f7f63f
...
@@ -34,6 +34,12 @@ module SlashCommands
...
@@ -34,6 +34,12 @@ module SlashCommands
@updates
[
:state_event
]
=
'reopen'
@updates
[
:state_event
]
=
'reopen'
end
end
desc
'Change title'
params
'<New title>'
command
:title
do
|
title_param
|
@updates
[
:title
]
=
title_param
end
desc
'Reassign'
desc
'Reassign'
params
'@user'
params
'@user'
command
:assign
,
:reassign
do
|
assignee_param
|
command
:assign
,
:reassign
do
|
assignee_param
|
...
...
doc/workflow/slash_commands.md
View file @
39f7f63f
...
@@ -13,6 +13,7 @@ do.
...
@@ -13,6 +13,7 @@ do.
|:---------------------------|:--------------------|:-------------|
|:---------------------------|:--------------------|:-------------|
|
`/close`
| None | Close the issue or merge request |
|
`/close`
| None | Close the issue or merge request |
|
`/open`
|
`/reopen`
| Reopen the issue or merge request |
|
`/open`
|
`/reopen`
| Reopen the issue or merge request |
|
`/title <New title>`
| None | Change title |
|
`/assign @username`
|
`/reassign`
| Reassign |
|
`/assign @username`
|
`/reassign`
| Reassign |
|
`/unassign`
|
`/remove_assignee`
| Remove assignee |
|
`/unassign`
|
`/remove_assignee`
| Remove assignee |
|
`/milestone %milestone`
| None | Change milestone |
|
`/milestone %milestone`
| None | Change milestone |
...
@@ -24,5 +25,5 @@ do.
...
@@ -24,5 +25,5 @@ do.
|
`/done`
| None | Mark todo as done |
|
`/done`
| None | Mark todo as done |
|
`/subscribe`
| None | Subscribe |
|
`/subscribe`
| None | Subscribe |
|
`/unsubscribe`
| None | Unsubscribe |
|
`/unsubscribe`
| None | Unsubscribe |
|
`/due_date
`
| None
| Set a due date |
|
`/due_date
<YYYY-MM-DD> | <N days>`
| None
| Set a due date |
|
`/clear_due_date`
| None | Remove due date |
|
`/clear_due_date`
| None | Remove due date |
spec/lib/gitlab/email/handler/create_note_handler_spec.rb
View file @
39f7f63f
...
@@ -64,10 +64,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler, lib: true do
...
@@ -64,10 +64,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler, lib: true do
context
'because the note was commands only'
do
context
'because the note was commands only'
do
let!
(
:email_raw
)
{
fixture_file
(
"emails/commands_only_reply.eml"
)
}
let!
(
:email_raw
)
{
fixture_file
(
"emails/commands_only_reply.eml"
)
}
context
'and current user cannot update noteable'
do
it
'raises a CommandsOnlyNoteError'
do
it
'raises a CommandsOnlyNoteError'
do
expect
{
receiver
.
execute
}.
not_to
raise_error
expect
{
receiver
.
execute
}.
to
raise_error
(
Gitlab
::
Email
::
InvalidNoteError
)
end
end
context
'and current user can update noteable'
do
before
do
project
.
team
<<
[
user
,
:developer
]
end
end
it
'raises a CommandsOnlyNoteError'
do
expect
{
receiver
.
execute
}.
not_to
raise_error
end
end
end
end
end
end
...
...
spec/services/slash_commands/interpret_service_spec.rb
View file @
39f7f63f
...
@@ -15,6 +15,7 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -15,6 +15,7 @@ describe SlashCommands::InterpretService, services: true do
is_expected
.
to
match_array
([
is_expected
.
to
match_array
([
:open
,
:reopen
,
:open
,
:reopen
,
:close
,
:close
,
:title
,
:assign
,
:reassign
,
:assign
,
:reassign
,
:unassign
,
:remove_assignee
,
:unassign
,
:remove_assignee
,
:milestone
,
:milestone
,
...
@@ -53,6 +54,14 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -53,6 +54,14 @@ describe SlashCommands::InterpretService, services: true do
end
end
end
end
shared_examples
'title command'
do
it
'populates title: "A brand new title" if content contains /title A brand new title'
do
changes
=
service
.
execute
(
content
,
issuable
)
expect
(
changes
).
to
eq
(
title:
'A brand new title'
)
end
end
shared_examples
'assign command'
do
shared_examples
'assign command'
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
changes
=
service
.
execute
(
content
,
issuable
)
changes
=
service
.
execute
(
content
,
issuable
)
...
@@ -190,6 +199,21 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -190,6 +199,21 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
merge_request
}
let
(
:issuable
)
{
merge_request
}
end
end
it_behaves_like
'title command'
do
let
(
:content
)
{
'/title A brand new title'
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'title command'
do
let
(
:content
)
{
'/title A brand new title'
}
let
(
:issuable
)
{
merge_request
}
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
'/title'
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'assign command'
do
it_behaves_like
'assign command'
do
let
(
:content
)
{
"/assign @
#{
user
.
username
}
"
}
let
(
:content
)
{
"/assign @
#{
user
.
username
}
"
}
let
(
:issuable
)
{
issue
}
let
(
:issuable
)
{
issue
}
...
@@ -200,16 +224,14 @@ describe SlashCommands::InterpretService, services: true do
...
@@ -200,16 +224,14 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
merge_request
}
let
(
:issuable
)
{
merge_request
}
end
end
it
'does not populate assignee_id if content contains /assign with an unknown user'
do
it_behaves_like
'empty command'
do
changes
=
service
.
execute
(
'/assign joe'
,
issue
)
let
(
:content
)
{
'/assign @abcd1234'
}
let
(
:issuable
)
{
issue
}
expect
(
changes
).
to
be_empty
end
end
it
'does not populate assignee_id if content contains /assign without user'
do
it_behaves_like
'empty command'
do
changes
=
service
.
execute
(
'/assign'
,
issue
)
let
(
:content
)
{
'/assign'
}
let
(
:issuable
)
{
issue
}
expect
(
changes
).
to
be_empty
end
end
it_behaves_like
'unassign command'
do
it_behaves_like
'unassign command'
do
...
...
spec/support/issuable_slash_commands_shared_examples.rb
View file @
39f7f63f
...
@@ -166,6 +166,43 @@ shared_examples 'issuable record that supports slash commands in its description
...
@@ -166,6 +166,43 @@ shared_examples 'issuable record that supports slash commands in its description
end
end
end
end
context
"with a note changing the
#{
issuable_type
}
's title"
do
context
"when current user can change title of
#{
issuable_type
}
"
do
it
"reopens the
#{
issuable_type
}
"
do
page
.
within
(
'.js-main-target-form'
)
do
fill_in
'note[note]'
,
with:
"/title Awesome new title"
click_button
'Comment'
end
expect
(
page
).
not_to
have_content
'/title'
expect
(
page
).
to
have_content
'Your commands are being executed.'
expect
(
issuable
.
reload
.
title
).
to
eq
'Awesome new title'
end
end
context
"when current user cannot change title of
#{
issuable_type
}
"
do
before
do
logout
login_with
(
guest
)
visit
public_send
(
"namespace_project_
#{
issuable_type
}
_path"
,
project
.
namespace
,
project
,
issuable
)
end
it
"does not reopen the
#{
issuable_type
}
"
do
current_title
=
issuable
.
title
page
.
within
(
'.js-main-target-form'
)
do
fill_in
'note[note]'
,
with:
"/title Awesome new title"
click_button
'Comment'
end
expect
(
page
).
not_to
have_content
'/title'
expect
(
page
).
not_to
have_content
'Your commands are being executed.'
expect
(
issuable
.
reload
.
title
).
not_to
eq
'Awesome new title'
end
end
end
context
"with a note marking the
#{
issuable_type
}
as todo"
do
context
"with a note marking the
#{
issuable_type
}
as todo"
do
it
"creates a new todo for the
#{
issuable_type
}
"
do
it
"creates a new todo for the
#{
issuable_type
}
"
do
page
.
within
(
'.js-main-target-form'
)
do
page
.
within
(
'.js-main-target-form'
)
do
...
...
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