Commit e4f38f3f authored by Retr0's avatar Retr0

Update the Discord integration embed

The embed now includes a timestamp of when the message
was sent and a color, defaulted to GitLab's logo color.

Changelog: changed
Helped-by: default avatarLuke Duncalfe <lduncalfe@eml.cc>
Helped-by: default avatarArturo Herrero <arturo.herrero@gmail.com>
parent df7369e5
......@@ -54,6 +54,8 @@ module Integrations
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")
embed.colour = 16543014 # The hex "fc6d26" as an Integer
embed.timestamp = Time.now.utc
end
end
rescue RestClient::Exception => error
......
......@@ -11,7 +11,9 @@ RSpec.describe Integrations::Discord do
embeds: [
include(
author: include(name: be_present),
description: be_present
description: be_present,
color: be_present,
timestamp: be_present
)
]
}
......@@ -47,15 +49,19 @@ RSpec.describe Integrations::Discord do
allow(client).to receive(:execute).and_yield(builder)
end
subject.execute(sample_data)
freeze_time do
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
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
),
color: 16543014,
timestamp: Time.now.utc.iso8601
)
)
end
end
context 'DNS rebind to local address' do
......
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