summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-11-21 20:27:58 +0000
committerRémy Coutable <remy@rymai.me>2016-11-21 20:27:58 +0000
commit2449d787ad32b399b79bf89c756bc9165232ceb0 (patch)
tree6cea4cf0ae0f88c50a48c7ba7643ce8f4d257689 /lib/gitlab
parent3c8d2148fc81cf75af322744221a0ff284216988 (diff)
parentd375e3f15b6f0340addb9a20e0c03a1f1fca413a (diff)
downloadgitlab-ce-2449d787ad32b399b79bf89c756bc9165232ceb0.tar.gz
Merge branch 'chatops-deploy-command' into 'master'
Add deploy chat command This adds a new ChatOps command: ``` /trigger deploy <environment> to <environment> ``` See merge request !7619
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/chat_commands/command.rb1
-rw-r--r--lib/gitlab/chat_commands/deploy.rb44
-rw-r--r--lib/gitlab/chat_commands/result.rb5
3 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb
index 5f131703d40..0ec358debc7 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::Deploy,
].freeze
def execute
diff --git a/lib/gitlab/chat_commands/deploy.rb b/lib/gitlab/chat_commands/deploy.rb
new file mode 100644
index 00000000000..c0b93cca68c
--- /dev/null
+++ b/lib/gitlab/chat_commands/deploy.rb
@@ -0,0 +1,44 @@
+module Gitlab
+ module ChatCommands
+ class Deploy < BaseCommand
+ def self.match(text)
+ /\Adeploy\s+(?<from>.*)\s+to+\s+(?<to>.*)\z/.match(text)
+ end
+
+ def self.help_message
+ 'deploy <environment> to <target-environment>'
+ end
+
+ def self.available?(project)
+ project.builds_enabled?
+ end
+
+ def self.allowed?(project, user)
+ can?(user, :create_deployment, project)
+ end
+
+ def execute(match)
+ from = match[:from]
+ to = match[:to]
+
+ actions = find_actions(from, to)
+ return unless actions.present?
+
+ if actions.one?
+ actions.first.play(current_user)
+ else
+ Result.new(:error, 'Too many actions defined')
+ end
+ end
+
+ private
+
+ def find_actions(from, to)
+ environment = project.environments.find_by(name: from)
+ return unless environment
+
+ environment.actions_for(to).select(&:starts_environment?)
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/chat_commands/result.rb b/lib/gitlab/chat_commands/result.rb
new file mode 100644
index 00000000000..324d7ef43a3
--- /dev/null
+++ b/lib/gitlab/chat_commands/result.rb
@@ -0,0 +1,5 @@
+module Gitlab
+ module ChatCommands
+ Result = Struct.new(:type, :message)
+ end
+end