Commit 7985ca9c authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'remove-chatops-buttons' into 'master'

Reduce noise from Chatops output

Closes #5140

See merge request gitlab-org/gitlab-ee!4938
parents ae921c03 a97a9370
...@@ -29,61 +29,26 @@ module Gitlab ...@@ -29,61 +29,26 @@ module Gitlab
# #
# output - The output produced by the chat command. # output - The output produced by the chat command.
def success(output) def success(output)
output = return if output.empty?
if output.empty?
'The command successfully completed but did not ' \
'write any data to STDOUT or STDERR.'
else
limit_output(output)
end
send_response( send_response(
text: message_text(output), text: message_text(limit_output(output)),
response_type: RESPONSE_TYPE, response_type: RESPONSE_TYPE
attachments: [
{
color: SUCCESS_COLOR,
actions: [
view_project_button,
view_pipeline_button,
view_build_button
]
}
]
) )
end end
# Sends the output for a build that failed. # Sends the output for a build that failed.
def failure def failure
send_response( send_response(
text: message_text('Sorry, the build failed!'), text: message_text("<#{build_url}|Sorry, the build failed!>"),
response_type: RESPONSE_TYPE, response_type: RESPONSE_TYPE
attachments: [
{
color: FAILURE_COLOR,
actions: [
view_project_button,
view_pipeline_button,
view_build_button
]
}
]
) )
end end
# Returns the output to send back after a command has been scheduled. # Returns the output to send back after a command has been scheduled.
def scheduled_output def scheduled_output
{ {
text: message_text('The command has been scheduled!'), text: message_text("<#{build_url}|The command has been scheduled!>")
attachments: [
{
actions: [
view_project_button,
view_pipeline_button,
view_build_button
]
}
]
} }
end end
...@@ -93,8 +58,7 @@ module Gitlab ...@@ -93,8 +58,7 @@ module Gitlab
if output.bytesize <= MESSAGE_SIZE_LIMIT if output.bytesize <= MESSAGE_SIZE_LIMIT
output output
else else
'The command output is too large to be sent back directly. ' \ "<#{build_url}|The output is too large to be sent back directly!>"
"The full output can be found at #{build_url}"
end end
end end
...@@ -106,36 +70,8 @@ module Gitlab ...@@ -106,36 +70,8 @@ module Gitlab
"#{mention_user}: #{output}" "#{mention_user}: #{output}"
end end
def view_project_button
{
type: :button,
text: 'View Project',
url: url_helpers.project_url(project)
}
end
def view_pipeline_button
{
type: :button,
text: 'View Pipeline',
url: url_helpers.project_pipeline_url(project, pipeline)
}
end
def view_build_button
{
type: :button,
text: 'View Build',
url: build_url
}
end
def build_url def build_url
url_helpers.project_build_url(project, build) ::Gitlab::Routing.url_helpers.project_build_url(project, build)
end
def url_helpers
::Gitlab::Routing.url_helpers
end end
end end
end end
......
...@@ -32,7 +32,7 @@ describe Gitlab::Chat::Responder::Slack do ...@@ -32,7 +32,7 @@ describe Gitlab::Chat::Responder::Slack do
it 'returns the output for a successful build' do it 'returns the output for a successful build' do
expect(responder) expect(responder)
.to receive(:send_response) .to receive(:send_response)
.with(hash_including(text: '<@U123>: hello', response_type: :in_channel)) .with(hash_including(text: /<@U123>:.+hello/, response_type: :in_channel))
responder.success('hello') responder.success('hello')
end end
...@@ -40,15 +40,13 @@ describe Gitlab::Chat::Responder::Slack do ...@@ -40,15 +40,13 @@ describe Gitlab::Chat::Responder::Slack do
it 'limits the output to a fixed size' do it 'limits the output to a fixed size' do
expect(responder) expect(responder)
.to receive(:send_response) .to receive(:send_response)
.with(hash_including(text: /The command output is too large/)) .with(hash_including(text: /The output is too large/))
responder.success('a' * 4000) responder.success('a' * 4000)
end end
it 'returns a generic message when the build did not produce any output' do it 'does not send a response if the output is empty' do
expect(responder) expect(responder).not_to receive(:send_response)
.to receive(:send_response)
.with(hash_including(text: /did not write any data to STDOUT/))
responder.success('') responder.success('')
end end
...@@ -58,7 +56,7 @@ describe Gitlab::Chat::Responder::Slack do ...@@ -58,7 +56,7 @@ describe Gitlab::Chat::Responder::Slack do
it 'returns the output for a failed build' do it 'returns the output for a failed build' do
expect(responder).to receive(:send_response).with( expect(responder).to receive(:send_response).with(
hash_including( hash_including(
text: '<@U123>: Sorry, the build failed!', text: /<@U123>:.+Sorry, the build failed!/,
response_type: :in_channel response_type: :in_channel
) )
) )
...@@ -71,7 +69,7 @@ describe Gitlab::Chat::Responder::Slack do ...@@ -71,7 +69,7 @@ describe Gitlab::Chat::Responder::Slack do
it 'returns the output for a scheduled build' do it 'returns the output for a scheduled build' do
output = responder.scheduled_output output = responder.scheduled_output
expect(output[:text]).to eq('<@U123>: The command has been scheduled!') expect(output[:text]).to match(/<@U123>:.+The command has been scheduled!/)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment