diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-22 15:05:52 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-22 15:05:52 +0200 |
commit | 97c42df3b804a37e659c3cda6bd8a52570f31366 (patch) | |
tree | 97c38db7f71a93a7b0db5ca2c682d6d17479cbdb /lib/gitlab/slash_commands/deploy.rb | |
parent | 3833f1dd84dfec844443a5b1d9ba2bd2b911c0bc (diff) | |
parent | 11716f310dcc495600f5a17e08456a1abb296482 (diff) | |
download | gitlab-ce-28717-additional-metrics-review-branch.tar.gz |
Merge remote-tracking branch 'upstream/master' into 28717-additional-metrics-review-branch28717-additional-metrics-review-branch
Diffstat (limited to 'lib/gitlab/slash_commands/deploy.rb')
-rw-r--r-- | lib/gitlab/slash_commands/deploy.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/slash_commands/deploy.rb b/lib/gitlab/slash_commands/deploy.rb new file mode 100644 index 00000000000..e71eb15d604 --- /dev/null +++ b/lib/gitlab/slash_commands/deploy.rb @@ -0,0 +1,50 @@ +module Gitlab + module SlashCommands + class Deploy < BaseCommand + def self.match(text) + /\Adeploy\s+(?<from>\S+.*)\s+to+\s+(?<to>\S+.*)\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) + + if actions.none? + Gitlab::SlashCommands::Presenters::Deploy.new(nil).no_actions + elsif actions.one? + action = play!(from, to, actions.first) + Gitlab::SlashCommands::Presenters::Deploy.new(action).present(from, to) + else + Gitlab::SlashCommands::Presenters::Deploy.new(actions).too_many_actions + end + end + + private + + def play!(from, to, action) + action.play(current_user) + end + + 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 |