add channel to webhooks (#915)

This commit is contained in:
Connor Turland 2016-11-05 09:34:50 -07:00 committed by GitHub
parent 887c3f7570
commit 0f85abfda2
5 changed files with 18 additions and 3 deletions

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
Webhooks::Slack::Base = Struct.new(:event) do
Webhooks::Slack::Base = Struct.new(:webhook, :event) do
include Routing
def username
@ -14,6 +14,10 @@ Webhooks::Slack::Base = Struct.new(:event) do
'something'
end
def channel
webhook.channel
end
def attachments
[{
title: attachment_title,

View file

@ -1,4 +1,9 @@
# frozen_string_literal: true
class WebhookSerializer < ActiveModel::Serializer
attributes :text, :username, :icon_url # , :attachments
attribute :channel, if: :has_channel?
def has_channel?
true if object.channel
end
end

View file

@ -11,7 +11,7 @@ class WebhookService
end
def webhook_object_for(webhook, event)
"Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event)
"Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(webhook, event)
end
end
end

View file

@ -0,0 +1,5 @@
class AddChannelToWebhook < ActiveRecord::Migration[5.0]
def change
add_column :webhooks, :channel, :string
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161013162214) do
ActiveRecord::Schema.define(version: 20161105160340) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -276,6 +276,7 @@ ActiveRecord::Schema.define(version: 20161013162214) do
t.string "kind", null: false
t.string "uri", null: false
t.text "event_types", default: [], array: true
t.string "channel"
t.index ["hookable_type", "hookable_id"], name: "index_webhooks_on_hookable_type_and_hookable_id", using: :btree
end