Skip to content
Snippets Groups Projects

Improve deploy message

Merged Kamil Trzcińśki requested to merge improve-deploy-message into master
4 files
+ 29
8
Compare changes
  • Side-by-side
  • Inline
Files
4
module Gitlab
module Gitlab
module ChatCommands
module ChatCommands
class Deploy < BaseCommand
class Deploy < BaseCommand
 
include Gitlab::Routing.url_helpers
 
def self.match(text)
def self.match(text)
/\Adeploy\s+(?<from>.*)\s+to+\s+(?<to>.*)\z/.match(text)
/\Adeploy\s+(?<from>.*)\s+to+\s+(?<to>.*)\z/.match(text)
end
end
@@ -25,7 +27,7 @@ module Gitlab
@@ -25,7 +27,7 @@ module Gitlab
return unless actions.present?
return unless actions.present?
if actions.one?
if actions.one?
actions.first.play(current_user)
play!(from, to, actions.first)
else
else
Result.new(:error, 'Too many actions defined')
Result.new(:error, 'Too many actions defined')
end
end
@@ -33,12 +35,23 @@ module Gitlab
@@ -33,12 +35,23 @@ module Gitlab
private
private
 
def play!(from, to, action)
 
new_action = action.play(current_user)
 
 
Result.new(:success, "Deployment from #{from} to #{to} started. Follow the progress: #{url(new_action)}.")
 
end
 
def find_actions(from, to)
def find_actions(from, to)
environment = project.environments.find_by(name: from)
environment = project.environments.find_by(name: from)
return unless environment
return unless environment
environment.actions_for(to).select(&:starts_environment?)
environment.actions_for(to).select(&:starts_environment?)
end
end
 
 
def url(subject)
 
polymorphic_url(
 
[ subject.project.namespace.becomes(Namespace), subject.project, subject ])
 
end
end
end
end
end
end
end
Loading