Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-11-09 18:07:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-09 18:07:50 +0300
commite38a99eb0725697297386dd0bb1045b1fd55493a (patch)
treee6298122cbb5418f59c140f4f9e303abdc0739b5 /lib/gitlab/slash_commands
parent7c41737ae53e3a237f356480ae04ec3ba182447b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/slash_commands')
-rw-r--r--lib/gitlab/slash_commands/application_help.rb13
-rw-r--r--lib/gitlab/slash_commands/command.rb12
-rw-r--r--lib/gitlab/slash_commands/incident_management/incident_command.rb17
-rw-r--r--lib/gitlab/slash_commands/incident_management/incident_new.rb33
-rw-r--r--lib/gitlab/slash_commands/presenters/help.rb11
-rw-r--r--lib/gitlab/slash_commands/presenters/incident_management/incident_new.rb15
6 files changed, 89 insertions, 12 deletions
diff --git a/lib/gitlab/slash_commands/application_help.rb b/lib/gitlab/slash_commands/application_help.rb
index 1a92346be15..bfdb65a816d 100644
--- a/lib/gitlab/slash_commands/application_help.rb
+++ b/lib/gitlab/slash_commands/application_help.rb
@@ -3,14 +3,9 @@
module Gitlab
module SlashCommands
class ApplicationHelp < BaseCommand
- def initialize(project, params)
- @project = project
- @params = params
- end
-
def execute
Gitlab::SlashCommands::Presenters::Help
- .new(project, commands)
+ .new(project, commands, params)
.present(trigger, params[:text])
end
@@ -21,7 +16,11 @@ module Gitlab
end
def commands
- Gitlab::SlashCommands::Command.commands
+ Gitlab::SlashCommands::Command.new(
+ project,
+ chat_name,
+ params
+ ).commands
end
end
end
diff --git a/lib/gitlab/slash_commands/command.rb b/lib/gitlab/slash_commands/command.rb
index 239479f99d2..265eda46489 100644
--- a/lib/gitlab/slash_commands/command.rb
+++ b/lib/gitlab/slash_commands/command.rb
@@ -3,8 +3,8 @@
module Gitlab
module SlashCommands
class Command < BaseCommand
- def self.commands
- [
+ def commands
+ commands = [
Gitlab::SlashCommands::IssueShow,
Gitlab::SlashCommands::IssueNew,
Gitlab::SlashCommands::IssueSearch,
@@ -14,6 +14,12 @@ module Gitlab
Gitlab::SlashCommands::Deploy,
Gitlab::SlashCommands::Run
]
+
+ if Feature.enabled?(:incident_declare_slash_command, current_user)
+ commands << Gitlab::SlashCommands::IncidentManagement::IncidentNew
+ end
+
+ commands
end
def execute
@@ -44,7 +50,7 @@ module Gitlab
private
def available_commands
- self.class.commands.keep_if do |klass|
+ commands.keep_if do |klass|
klass.available?(project)
end
end
diff --git a/lib/gitlab/slash_commands/incident_management/incident_command.rb b/lib/gitlab/slash_commands/incident_management/incident_command.rb
new file mode 100644
index 00000000000..13d371151f9
--- /dev/null
+++ b/lib/gitlab/slash_commands/incident_management/incident_command.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module SlashCommands
+ module IncidentManagement
+ class IncidentCommand < BaseCommand
+ def self.available?(project)
+ true
+ end
+
+ def collection
+ IssuesFinder.new(current_user, project_id: project.id, issue_types: :incident).execute
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/slash_commands/incident_management/incident_new.rb b/lib/gitlab/slash_commands/incident_management/incident_new.rb
new file mode 100644
index 00000000000..ce148f888b8
--- /dev/null
+++ b/lib/gitlab/slash_commands/incident_management/incident_new.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module SlashCommands
+ module IncidentManagement
+ class IncidentNew < IncidentCommand
+ def self.help_message
+ 'incident declare'
+ end
+
+ def self.allowed?(project, user)
+ Feature.enabled?(:incident_declare_slash_command, user) && can?(user, :create_incident, project)
+ end
+
+ def self.match(text)
+ text == 'incident declare'
+ end
+
+ def execute(_match)
+ response = ServiceResponse.success(message: 'It works!')
+
+ presenter.present(response.message)
+ end
+
+ private
+
+ def presenter
+ Gitlab::SlashCommands::Presenters::IncidentManagement::IncidentNew.new
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/slash_commands/presenters/help.rb b/lib/gitlab/slash_commands/presenters/help.rb
index 71bc0dc0123..61b36308d20 100644
--- a/lib/gitlab/slash_commands/presenters/help.rb
+++ b/lib/gitlab/slash_commands/presenters/help.rb
@@ -4,9 +4,10 @@ module Gitlab
module SlashCommands
module Presenters
class Help < Presenters::Base
- def initialize(project, commands)
+ def initialize(project, commands, params = {})
@project = project
@commands = commands
+ @params = params
end
def present(trigger, text)
@@ -66,7 +67,13 @@ module Gitlab
def full_commands_message(trigger)
list = @commands
- .map { |command| "#{trigger} #{command.help_message}" }
+ .map do |command|
+ if command < Gitlab::SlashCommands::IncidentManagement::IncidentCommand
+ "#{@params[:command]} #{command.help_message}"
+ else
+ "#{trigger} #{command.help_message}"
+ end
+ end
.join("\n")
<<~MESSAGE
diff --git a/lib/gitlab/slash_commands/presenters/incident_management/incident_new.rb b/lib/gitlab/slash_commands/presenters/incident_management/incident_new.rb
new file mode 100644
index 00000000000..5030c8282db
--- /dev/null
+++ b/lib/gitlab/slash_commands/presenters/incident_management/incident_new.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module SlashCommands
+ module Presenters
+ module IncidentManagement
+ class IncidentNew < Presenters::Base
+ def present(message)
+ ephemeral_response(text: message)
+ end
+ end
+ end
+ end
+ end
+end