diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-29 14:04:17 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-29 14:04:17 +0300 |
commit | 35212deb062dda60220a9a0929c26196c1c598b5 (patch) | |
tree | 1f8eaa14f3774c1dfe38b96e964bbff9eb1f2b91 /lib/gitlab/chat_commands | |
parent | 63f5c4ea5436f312693da0559602803c733dc9cb (diff) | |
parent | 6a08de7386fd41c9bbe27c32338328c6e6b40027 (diff) |
Merge branch 'zj-issue-search-slash-command' into 'master'
Add issue search slash command
See merge request !7752
Diffstat (limited to 'lib/gitlab/chat_commands')
-rw-r--r-- | lib/gitlab/chat_commands/base_command.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/command.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/issue_command.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/issue_search.rb | 17 |
4 files changed, 20 insertions, 8 deletions
diff --git a/lib/gitlab/chat_commands/base_command.rb b/lib/gitlab/chat_commands/base_command.rb index e59d69b72b9..25da8474e95 100644 --- a/lib/gitlab/chat_commands/base_command.rb +++ b/lib/gitlab/chat_commands/base_command.rb @@ -40,9 +40,7 @@ module Gitlab private def find_by_iid(iid) - resource = collection.find_by(iid: iid) - - readable?(resource) ? resource : nil + collection.find_by(iid: iid) end end end diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index 0ec358debc7..b0d3fdbc48a 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -4,6 +4,7 @@ module Gitlab COMMANDS = [ Gitlab::ChatCommands::IssueShow, Gitlab::ChatCommands::IssueCreate, + Gitlab::ChatCommands::IssueSearch, Gitlab::ChatCommands::Deploy, ].freeze diff --git a/lib/gitlab/chat_commands/issue_command.rb b/lib/gitlab/chat_commands/issue_command.rb index f1bc36239d5..84de3e44c70 100644 --- a/lib/gitlab/chat_commands/issue_command.rb +++ b/lib/gitlab/chat_commands/issue_command.rb @@ -6,11 +6,7 @@ module Gitlab end def collection - project.issues - end - - def readable?(issue) - self.class.can?(current_user, :read_issue, issue) + IssuesFinder.new(current_user, project_id: project.id).execute end end end diff --git a/lib/gitlab/chat_commands/issue_search.rb b/lib/gitlab/chat_commands/issue_search.rb new file mode 100644 index 00000000000..51bf80c800b --- /dev/null +++ b/lib/gitlab/chat_commands/issue_search.rb @@ -0,0 +1,17 @@ +module Gitlab + module ChatCommands + class IssueSearch < IssueCommand + def self.match(text) + /\Aissue\s+search\s+(?<query>.*)/.match(text) + end + + def self.help_message + "issue search <your query>" + end + + def execute(match) + collection.search(match[:query]).limit(QUERY_LIMIT) + end + end + end +end |