diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-21 21:53:39 +0000 |
---|---|---|
committer | Alejandro Rodríguez <alejorro70@gmail.com> | 2016-11-22 00:27:13 +0000 |
commit | b0c5d3577f94b2cfc55c340c724a3ee0fe0b6d96 (patch) | |
tree | 2905fd2ccb59b94e1fe4ab4469c0fc69200de2cd | |
parent | 4d5cae134abf2b2d99b87c4d34693166763dfb7a (diff) | |
download | gitlab-ce-b0c5d3577f94b2cfc55c340c724a3ee0fe0b6d96.tar.gz |
Merge branch 'improve-deploy-message' into 'master'
Improve deploy message
## What does this MR do?
Improves deploy message to make it more descriptive and useable then what is already offered by deploy command.
## Does this MR meet the acceptance criteria?
- [ ] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- Tests
- [ ] Added for this feature/bug
- [ ] All builds are passing
- [ ] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
## What are the relevant issue numbers?
See merge request !7629
-rw-r--r-- | lib/gitlab/chat_commands/deploy.rb | 15 | ||||
-rw-r--r-- | lib/mattermost/presenter.rb | 7 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/command_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/deploy_spec.rb | 13 |
4 files changed, 29 insertions, 8 deletions
diff --git a/lib/gitlab/chat_commands/deploy.rb b/lib/gitlab/chat_commands/deploy.rb index c0b93cca68c..0eed1fce0dc 100644 --- a/lib/gitlab/chat_commands/deploy.rb +++ b/lib/gitlab/chat_commands/deploy.rb @@ -1,6 +1,8 @@ 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 @@ -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 @@ -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 diff --git a/lib/mattermost/presenter.rb b/lib/mattermost/presenter.rb index 6b12081575d..67eda983a74 100644 --- a/lib/mattermost/presenter.rb +++ b/lib/mattermost/presenter.rb @@ -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 diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb index 924b4b7b101..bfc6818ac08 100644 --- a/spec/lib/gitlab/chat_commands/command_spec.rb +++ b/spec/lib/gitlab/chat_commands/command_spec.rb @@ -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 diff --git a/spec/lib/gitlab/chat_commands/deploy_spec.rb b/spec/lib/gitlab/chat_commands/deploy_spec.rb index 26741367e63..bd8099c92da 100644 --- a/spec/lib/gitlab/chat_commands/deploy_spec.rb +++ b/spec/lib/gitlab/chat_commands/deploy_spec.rb @@ -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 @@ -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 @@ -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 |