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:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-11-21 15:47:18 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-11-21 18:28:23 +0300
commit1d16f137d93576385e403f5caf5f64bfe0b3a647 (patch)
tree7875514900e1e1d329f175d8890e7718f886e38d /lib/gitlab/chat_commands
parentc99522f21eed933f6a6b7214ea659e3ab13ef188 (diff)
Add deploy chat command [ci skip]
Diffstat (limited to 'lib/gitlab/chat_commands')
-rw-r--r--lib/gitlab/chat_commands/deploy.rb34
-rw-r--r--lib/gitlab/chat_commands/result.rb5
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/chat_commands/deploy.rb b/lib/gitlab/chat_commands/deploy.rb
new file mode 100644
index 00000000000..8165d52575d
--- /dev/null
+++ b/lib/gitlab/chat_commands/deploy.rb
@@ -0,0 +1,34 @@
+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.allowed?(project, user)
+ can?(user, :create_deployment, project)
+ end
+
+ def execute(match)
+ from = match[:from]
+ to = match[:to]
+
+ environment = project.environments.find_by(name: from)
+ return unless environment
+
+ actions = environment.actions_for(to)
+ return unless actions.any?
+
+ if actions.one?
+ actions.first.play(current_user)
+ else
+ Result.new(:error, 'Too many actions defined')
+ end
+ 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