提交 846d8460 编写于 作者: B blackst0ne

Add Discord integration

上级 af80955b
......@@ -204,6 +204,9 @@ gem 'redis-rails', '~> 5.0.2'
gem 'redis', '~> 3.2'
gem 'connection_pool', '~> 2.0'
# Discord integration
gem 'discordrb-webhooks', '~> 3.3', github: 'blackst0ne/discordrb', require: false
# HipChat integration
gem 'hipchat', '~> 1.5.0'
......
GIT
remote: git://github.com/blackst0ne/discordrb.git
revision: 2de6ec4dda1e2ea2966f1ced063698d7c5fc5225
specs:
discordrb-webhooks (3.3.0)
rest-client (~> 2.0)
GEM
remote: https://rubygems.org/
specs:
......@@ -972,6 +979,7 @@ DEPENDENCIES
devise (~> 4.4)
devise-two-factor (~> 3.0.0)
diffy (~> 3.1.0)
discordrb-webhooks (~> 3.3)!
doorkeeper (~> 4.3)
doorkeeper-openid_connect (~> 1.5)
ed25519 (~> 1.2)
......
GIT
remote: git://github.com/blackst0ne/discordrb.git
revision: 2de6ec4dda1e2ea2966f1ced063698d7c5fc5225
specs:
discordrb-webhooks (3.3.0)
rest-client (~> 2.0)
GEM
remote: https://rubygems.org/
specs:
......@@ -981,6 +988,7 @@ DEPENDENCIES
devise (~> 4.4)
devise-two-factor (~> 3.0.0)
diffy (~> 3.1.0)
discordrb-webhooks (~> 3.3)!
doorkeeper (~> 4.3)
doorkeeper-openid_connect (~> 1.5)
ed25519 (~> 1.2)
......
......@@ -135,6 +135,7 @@ class Project < ActiveRecord::Base
# Project services
has_one :campfire_service
has_one :discord_service
has_one :drone_ci_service
has_one :emails_on_push_service
has_one :pipelines_email_service
......
# frozen_string_literal: true
require "discordrb/webhooks"
class DiscordService < ChatNotificationService
def title
"Discord Notifications"
end
def description
"Receive event notifications in Discord"
end
def self.to_param
"discord"
end
def help
"This service sends notifications about projects events to Discord channels.<br />
To set up this service:
<ol>
<li><a href='ADD-DISCORD-LINK-HERE'>Setup a custom Incoming Webhook</a>.</li>
<li>Paste the <strong>Webhook URL</strong> into the field below.</li>
<li>Select events below to enable notifications.</li>
</ol>"
end
def webhook_placeholder
"https://discordapp.com/api/webhooks/..."
end
def event_field(event)
end
def default_channel_placeholder
end
def default_fields
[
{ type: "text", name: "webhook", placeholder: "e.g. #{webhook_placeholder}" },
{ type: "checkbox", name: "notify_only_broken_pipelines" },
{ type: "checkbox", name: "notify_only_default_branch" }
]
end
private
def notify(message, opts)
client = Discordrb::Webhooks::Client.new(url: webhook)
client.execute do |builder|
builder.content = message.pretext
# builder.add_embed do |embed|
# embed.title = 'Embed title'
# embed.description = 'Embed description'
# embed.timestamp = Time.now
# end
end
end
def custom_data(data)
super(data).merge(markdown: true)
end
end
......@@ -253,6 +253,7 @@ class Service < ActiveRecord::Base
bugzilla
campfire
custom_issue_tracker
discord
drone_ci
emails_on_push
external_wiki
......
......@@ -298,6 +298,14 @@ module API
desc: 'Title'
}
],
'discord' => [
{
required: true,
name: :webhook,
type: String,
desc: 'Discord webhook. e.g. https://discordapp.com/api/webhooks/…'
}
],
'drone-ci' => [
{
required: true,
......@@ -677,6 +685,7 @@ module API
BuildkiteService,
CampfireService,
CustomIssueTrackerService,
DiscordService,
DroneCiService,
EmailsOnPushService,
ExternalWikiService,
......
......@@ -198,6 +198,7 @@ project:
- last_event
- services
- campfire_service
- discord_service
- drone_ci_service
- emails_on_push_service
- pipelines_email_service
......
......@@ -32,6 +32,7 @@ describe Project do
it { is_expected.to have_one(:asana_service) }
it { is_expected.to have_many(:boards) }
it { is_expected.to have_one(:campfire_service) }
it { is_expected.to have_one(:discord_service) }
it { is_expected.to have_one(:drone_ci_service) }
it { is_expected.to have_one(:emails_on_push_service) }
it { is_expected.to have_one(:pipelines_email_service) }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册