Commit 0eef93f9 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'improve-discord-messages' into 'master'

Improve discord messages

See merge request gitlab-org/gitlab!27812
parents 0c342a8c f91a0c01
......@@ -3,6 +3,8 @@
require "discordrb/webhooks"
class DiscordService < ChatNotificationService
ATTACHMENT_REGEX = /: (?<entry>.*?)\n - (?<name>.*)\n*/.freeze
def title
s_("DiscordService|Discord Notifications")
end
......@@ -52,7 +54,10 @@ class DiscordService < ChatNotificationService
client = Discordrb::Webhooks::Client.new(url: webhook)
client.execute do |builder|
builder.content = message.pretext
builder.add_embed do |embed|
embed.author = Discordrb::Webhooks::EmbedAuthor.new(name: message.user_name, icon_url: message.user_avatar)
embed.description = (message.pretext + "\n" + Array.wrap(message.attachments).join("\n")).gsub(ATTACHMENT_REGEX, " \\k<entry> - \\k<name>\n")
end
end
end
......
---
title: Update discord notifications to be a single embed and include log messages
merge_request: 27812
author: Sam Bingner
type: fixed
......@@ -31,6 +31,24 @@ describe DiscordService do
WebMock.stub_request(:post, webhook_url)
end
it 'uses the right embed parameters' do
builder = Discordrb::Webhooks::Builder.new
allow_next_instance_of(Discordrb::Webhooks::Client) do |client|
allow(client).to receive(:execute).and_yield(builder)
end
subject.execute(sample_data)
expect(builder.to_json_hash[:embeds].first).to include(
description: start_with("#{user.name} pushed to branch [master](http://localhost/#{project.namespace.path}/#{project.path}/commits/master) of"),
author: hash_including(
icon_url: start_with('https://www.gravatar.com/avatar/'),
name: user.name
)
)
end
context 'DNS rebind to local address' do
before do
stub_dns(webhook_url, ip_address: '192.168.2.120')
......
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