Skip to content
Snippets Groups Projects
Commit 41aa605d authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Improve deploy command message

parent d375e3f1
Branches
Tags
1 merge request!7629Improve deploy message
Pipeline #
module Gitlab
module ChatCommands
class Deploy < BaseCommand
include Gitlab::Routing.url_helpers
def self.match(text)
/\Adeploy\s+(?<from>.*)\s+to+\s+(?<to>.*)\z/.match(text)
end
Loading
Loading
@@ -25,7 +27,7 @@ module Gitlab
return unless actions.present?
 
if actions.one?
actions.first.play(current_user)
play!(from, to, actions.first)
else
Result.new(:error, 'Too many actions defined')
end
Loading
Loading
@@ -33,12 +35,23 @@ module Gitlab
 
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)
environment = project.environments.find_by(name: from)
return unless environment
 
environment.actions_for(to).select(&:starts_environment?)
end
def url(subject)
polymorphic_url(
[ subject.project.namespace.becomes(Namespace), subject.project, subject ])
end
end
end
end
Loading
Loading
@@ -49,7 +49,12 @@ module Mattermost
private
 
def show_result(result)
ephemeral_response(result.message)
case result.type
when :success
in_channel_response(result.message)
else
ephemeral_response(result.message)
end
end
 
def not_found
Loading
Loading
Loading
Loading
@@ -74,7 +74,7 @@ describe Gitlab::ChatCommands::Command, service: true do
end
 
it 'returns action' do
expect(subject[:text]).to include(manual.name)
expect(subject[:text]).to include('Deployment from staging to production started')
expect(subject[:response_type]).to be(:in_channel)
end
 
Loading
Loading
Loading
Loading
@@ -36,8 +36,9 @@ describe Gitlab::ChatCommands::Deploy, service: true do
create(:ci_build, :manual, project: project, pipeline: build.pipeline, name: 'first', environment: 'production')
end
 
it 'returns action' do
expect(subject).to eq(manual1)
it 'returns success result' do
expect(subject.type).to eq(:success)
expect(subject.message).to include('Deployment from staging to production started')
end
 
context 'when duplicate action exists' do
Loading
Loading
@@ -46,7 +47,8 @@ describe Gitlab::ChatCommands::Deploy, service: true do
end
 
it 'returns error' do
expect(subject.message).to eq('Too many actions defined')
expect(subject.type).to eq(:error)
expect(subject.message).to include('Too many actions defined')
end
end
 
Loading
Loading
@@ -57,8 +59,9 @@ describe Gitlab::ChatCommands::Deploy, service: true do
name: 'teardown', environment: 'production')
end
 
it 'returns error' do
expect(subject).to eq(manual1)
it 'returns success result' do
expect(subject.type).to eq(:success)
expect(subject.message).to include('Deployment from staging to production started')
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment