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
#
# output - The output produced by the chat command.
def success(output)
output =
if output.empty?
'The command successfully completed but did not ' \
'write any data to STDOUT or STDERR.'
else
limit_output(output)
end
return if output.empty?
send_response(
text: message_text(output),
response_type: RESPONSE_TYPE,
attachments: [
{
color: SUCCESS_COLOR,
actions: [
view_project_button,
view_pipeline_button,
view_build_button
]
}
]
text: message_text(limit_output(output)),
response_type: RESPONSE_TYPE
)
end
# Sends the output for a build that failed.
def failure
send_response(
text: message_text('Sorry, the build failed!'),
response_type: RESPONSE_TYPE,
attachments: [
{
color: FAILURE_COLOR,
actions: [
view_project_button,
view_pipeline_button,
view_build_button
]
}
]
text: message_text("<#{build_url}|Sorry, the build failed!>"),
response_type: RESPONSE_TYPE
)
end
# Returns the output to send back after a command has been scheduled.
def scheduled_output
{
text: message_text('The command has been scheduled!'),
attachments: [
{
actions: [
view_project_button,
view_pipeline_button,
view_build_button
]
}
]
text: message_text("<#{build_url}|The command has been scheduled!>")
}
end
......@@ -93,8 +58,7 @@ module Gitlab
if output.bytesize <= MESSAGE_SIZE_LIMIT
output
else
'The command output is too large to be sent back directly. ' \
"The full output can be found at #{build_url}"
"<#{build_url}|The output is too large to be sent back directly!>"
end
end
......@@ -106,36 +70,8 @@ module Gitlab
"#{mention_user}: #{output}"
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
url_helpers.project_build_url(project, build)
end
def url_helpers
::Gitlab::Routing.url_helpers
::Gitlab::Routing.url_helpers.project_build_url(project, build)
end
end
end
......
......@@ -32,7 +32,7 @@ describe Gitlab::Chat::Responder::Slack do
it 'returns the output for a successful build' do
expect(responder)
.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')
end
......@@ -40,15 +40,13 @@ describe Gitlab::Chat::Responder::Slack do
it 'limits the output to a fixed size' do
expect(responder)
.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)
end
it 'returns a generic message when the build did not produce any output' do
expect(responder)
.to receive(:send_response)
.with(hash_including(text: /did not write any data to STDOUT/))
it 'does not send a response if the output is empty' do
expect(responder).not_to receive(:send_response)
responder.success('')
end
......@@ -58,7 +56,7 @@ describe Gitlab::Chat::Responder::Slack do
it 'returns the output for a failed build' do
expect(responder).to receive(:send_response).with(
hash_including(
text: '<@U123>: Sorry, the build failed!',
text: /<@U123>:.+Sorry, the build failed!/,
response_type: :in_channel
)
)
......@@ -71,7 +69,7 @@ describe Gitlab::Chat::Responder::Slack do
it 'returns the output for a scheduled build' do
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
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