Commit 846d8460 authored by blackst0ne's avatar blackst0ne

Add Discord integration

parent af80955b
...@@ -204,6 +204,9 @@ gem 'redis-rails', '~> 5.0.2' ...@@ -204,6 +204,9 @@ gem 'redis-rails', '~> 5.0.2'
gem 'redis', '~> 3.2' gem 'redis', '~> 3.2'
gem 'connection_pool', '~> 2.0' gem 'connection_pool', '~> 2.0'
# Discord integration
gem 'discordrb-webhooks', '~> 3.3', github: 'blackst0ne/discordrb', require: false
# HipChat integration # HipChat integration
gem 'hipchat', '~> 1.5.0' 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 GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
...@@ -972,6 +979,7 @@ DEPENDENCIES ...@@ -972,6 +979,7 @@ DEPENDENCIES
devise (~> 4.4) devise (~> 4.4)
devise-two-factor (~> 3.0.0) devise-two-factor (~> 3.0.0)
diffy (~> 3.1.0) diffy (~> 3.1.0)
discordrb-webhooks (~> 3.3)!
doorkeeper (~> 4.3) doorkeeper (~> 4.3)
doorkeeper-openid_connect (~> 1.5) doorkeeper-openid_connect (~> 1.5)
ed25519 (~> 1.2) ed25519 (~> 1.2)
......
GIT
remote: git://github.com/blackst0ne/discordrb.git
revision: 2de6ec4dda1e2ea2966f1ced063698d7c5fc5225
specs:
discordrb-webhooks (3.3.0)
rest-client (~> 2.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
...@@ -981,6 +988,7 @@ DEPENDENCIES ...@@ -981,6 +988,7 @@ DEPENDENCIES
devise (~> 4.4) devise (~> 4.4)
devise-two-factor (~> 3.0.0) devise-two-factor (~> 3.0.0)
diffy (~> 3.1.0) diffy (~> 3.1.0)
discordrb-webhooks (~> 3.3)!
doorkeeper (~> 4.3) doorkeeper (~> 4.3)
doorkeeper-openid_connect (~> 1.5) doorkeeper-openid_connect (~> 1.5)
ed25519 (~> 1.2) ed25519 (~> 1.2)
......
...@@ -135,6 +135,7 @@ class Project < ActiveRecord::Base ...@@ -135,6 +135,7 @@ class Project < ActiveRecord::Base
# Project services # Project services
has_one :campfire_service has_one :campfire_service
has_one :discord_service
has_one :drone_ci_service has_one :drone_ci_service
has_one :emails_on_push_service has_one :emails_on_push_service
has_one :pipelines_email_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 ...@@ -253,6 +253,7 @@ class Service < ActiveRecord::Base
bugzilla bugzilla
campfire campfire
custom_issue_tracker custom_issue_tracker
discord
drone_ci drone_ci
emails_on_push emails_on_push
external_wiki external_wiki
......
...@@ -298,6 +298,14 @@ module API ...@@ -298,6 +298,14 @@ module API
desc: 'Title' desc: 'Title'
} }
], ],
'discord' => [
{
required: true,
name: :webhook,
type: String,
desc: 'Discord webhook. e.g. https://discordapp.com/api/webhooks/…'
}
],
'drone-ci' => [ 'drone-ci' => [
{ {
required: true, required: true,
...@@ -677,6 +685,7 @@ module API ...@@ -677,6 +685,7 @@ module API
BuildkiteService, BuildkiteService,
CampfireService, CampfireService,
CustomIssueTrackerService, CustomIssueTrackerService,
DiscordService,
DroneCiService, DroneCiService,
EmailsOnPushService, EmailsOnPushService,
ExternalWikiService, ExternalWikiService,
......
...@@ -198,6 +198,7 @@ project: ...@@ -198,6 +198,7 @@ project:
- last_event - last_event
- services - services
- campfire_service - campfire_service
- discord_service
- drone_ci_service - drone_ci_service
- emails_on_push_service - emails_on_push_service
- pipelines_email_service - pipelines_email_service
......
...@@ -32,6 +32,7 @@ describe Project do ...@@ -32,6 +32,7 @@ describe Project do
it { is_expected.to have_one(:asana_service) } it { is_expected.to have_one(:asana_service) }
it { is_expected.to have_many(:boards) } it { is_expected.to have_many(:boards) }
it { is_expected.to have_one(:campfire_service) } 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(:drone_ci_service) }
it { is_expected.to have_one(:emails_on_push_service) } it { is_expected.to have_one(:emails_on_push_service) }
it { is_expected.to have_one(:pipelines_email_service) } it { is_expected.to have_one(:pipelines_email_service) }
......
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