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
23db6449
Commit
23db6449
authored
Aug 10, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for no-op slash commands that appear in autocomplete
The first one is /cc Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
e0216044
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
14 deletions
+35
-14
interpret_service.rb
app/services/slash_commands/interpret_service.rb
+9
-1
dsl.rb
lib/gitlab/slash_commands/dsl.rb
+11
-3
dsl_spec.rb
spec/lib/gitlab/slash_commands/dsl_spec.rb
+11
-5
extractor_spec.rb
spec/lib/gitlab/slash_commands/extractor_spec.rb
+2
-2
issuable_slash_commands_shared_examples.rb
spec/support/issuable_slash_commands_shared_examples.rb
+2
-3
No files found.
app/services/slash_commands/interpret_service.rb
View file @
23db6449
...
...
@@ -117,7 +117,7 @@ module SlashCommands
return
unless
noteable
.
respond_to?
(
:due_date
)
due_date
=
begin
if
due_date_param
.
downcase
==
'tomorrow'
if
due_date_param
.
casecmp
(
'tomorrow'
).
zero?
Date
.
tomorrow
else
Time
.
now
+
ChronicDuration
.
parse
(
due_date_param
)
...
...
@@ -136,6 +136,14 @@ module SlashCommands
@updates
[
:due_date
]
=
nil
end
# This is a dummy command, so that it appears in the autocomplete commands
desc
'CC'
params
'@user'
noop
true
command
:cc
do
return
end
def
find_label_ids
(
labels_param
)
extract_references
(
labels_param
,
:label
).
map
(
&
:id
)
end
...
...
lib/gitlab/slash_commands/dsl.rb
View file @
23db6449
...
...
@@ -14,8 +14,10 @@ module Gitlab
def
command_names
command_definitions
.
flat_map
do
|
command_definition
|
[
command_definition
[
:name
],
command_definition
[
:aliases
]].
flatten
end
unless
command_definition
[
:noop
]
[
command_definition
[
:name
],
command_definition
[
:aliases
]].
flatten
end
end
.
compact
end
# Allows to give a description to the next slash command
...
...
@@ -28,6 +30,11 @@ module Gitlab
@params
=
params
end
# Allows to define if a command is a no-op, but should appear in autocomplete
def
noop
(
noop
)
@noop
=
noop
end
# Registers a new command which is recognizeable
# from body of email or comment.
# Example:
...
...
@@ -63,7 +70,8 @@ module Gitlab
name:
command_name
,
aliases:
aliases
,
description:
@description
||
''
,
params:
@params
||
[]
params:
@params
||
[],
noop:
@noop
||
false
}
@command_definitions
<<
command_definition
...
...
spec/lib/gitlab/slash_commands/dsl_spec.rb
View file @
23db6449
...
...
@@ -29,6 +29,11 @@ describe Gitlab::SlashCommands::Dsl do
command
:wildcard
do
|*
args
|
args
end
noop
true
command
:cc
do
|*
args
|
args
end
end
end
let
(
:dummy
)
{
DummyClass
.
new
}
...
...
@@ -36,11 +41,12 @@ describe Gitlab::SlashCommands::Dsl do
describe
'.command_definitions'
do
it
'returns an array with commands definitions'
do
expected
=
[
{
name: :no_args
,
aliases:
[
:none
],
description:
'A command with no args'
,
params:
[]
},
{
name: :returning
,
aliases:
[],
description:
'A command returning a value'
,
params:
[]
},
{
name: :one_arg
,
aliases:
[
:once
,
:first
],
description:
''
,
params:
[
'The first argument'
]
},
{
name: :two_args
,
aliases:
[],
description:
'A command with two args'
,
params:
[
'The first argument'
,
'The second argument'
]
},
{
name: :wildcard
,
aliases:
[],
description:
''
,
params:
[]
}
{
name: :no_args
,
aliases:
[
:none
],
description:
'A command with no args'
,
params:
[],
noop:
false
},
{
name: :returning
,
aliases:
[],
description:
'A command returning a value'
,
params:
[],
noop:
false
},
{
name: :one_arg
,
aliases:
[
:once
,
:first
],
description:
''
,
params:
[
'The first argument'
],
noop:
false
},
{
name: :two_args
,
aliases:
[],
description:
'A command with two args'
,
params:
[
'The first argument'
,
'The second argument'
],
noop:
false
},
{
name: :wildcard
,
aliases:
[],
description:
''
,
params:
[],
noop:
false
},
{
name: :cc
,
aliases:
[],
description:
''
,
params:
[],
noop:
true
}
]
expect
(
DummyClass
.
command_definitions
).
to
eq
expected
...
...
spec/lib/gitlab/slash_commands/extractor_spec.rb
View file @
23db6449
...
...
@@ -175,7 +175,7 @@ describe Gitlab::SlashCommands::Extractor do
end
it
'does not extract commands inside a blockcode'
do
msg
=
msg
=
"Hello
\r\n
```
\r\n
This is some text
\r\n
/close
\r\n
/assign @user
\r\n
```
\r\n\r\n
World"
msg
=
"Hello
\r\n
```
\r\n
This is some text
\r\n
/close
\r\n
/assign @user
\r\n
```
\r\n\r\n
World"
expected
=
msg
.
delete
(
"
\r
"
)
commands
=
extractor
.
extract_commands!
(
msg
)
...
...
@@ -193,7 +193,7 @@ describe Gitlab::SlashCommands::Extractor do
end
it
'does not extract commands inside a HTML tag'
do
msg
=
msg
=
"Hello
\r\n
<div>
\r\n
This is some text
\r\n
/close
\r\n
/assign @user
\r\n
</div>
\r\n\r\n
World"
msg
=
"Hello
\r\n
<div>
\r\n
This is some text
\r\n
/close
\r\n
/assign @user
\r\n
</div>
\r\n\r\n
World"
expected
=
msg
.
delete
(
"
\r
"
)
commands
=
extractor
.
extract_commands!
(
msg
)
...
...
spec/support/issuable_slash_commands_shared_examples.rb
View file @
23db6449
...
...
@@ -28,7 +28,7 @@ shared_examples 'issuable record that supports slash commands in its description
issuable
=
project
.
public_send
(
issuable_type
.
to_s
.
pluralize
).
first
expect
(
issuable
.
description
).
to
eq
"bug description
\
r\
n
"
expect
(
issuable
.
description
).
to
eq
"bug description
\n
"
expect
(
issuable
.
labels
).
to
eq
[
label_bug
]
expect
(
issuable
.
milestone
).
to
eq
milestone
expect
(
page
).
to
have_content
'bug 345'
...
...
@@ -57,7 +57,7 @@ shared_examples 'issuable record that supports slash commands in its description
issuable
.
reload
note
=
issuable
.
notes
.
user
.
first
expect
(
note
.
note
).
to
eq
"Awesome!
\
r\
n
"
expect
(
note
.
note
).
to
eq
"Awesome!
\n
"
expect
(
issuable
.
assignee
).
to
eq
assignee
expect
(
issuable
.
labels
).
to
eq
[
label_bug
]
expect
(
issuable
.
milestone
).
to
eq
milestone
...
...
@@ -189,7 +189,6 @@ shared_examples 'issuable record that supports slash commands in its description
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'
...
...
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