Class: Tokite::Hook
- Inherits:
-
Object
- Object
- Tokite::Hook
- Defined in:
- app/models/tokite/hook.rb
Constant Summary collapse
- HOOK_EVENTS =
{ "pull_request" => HookEvent::PullRequest, "issues" => HookEvent::Issues, "issue_comment" => HookEvent::IssueComment, }.freeze
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Class Method Summary collapse
Instance Method Summary collapse
- #fire! ⇒ Object
-
#initialize(event) ⇒ Hook
constructor
A new instance of Hook.
- #notify!(payload) ⇒ Object
Constructor Details
#initialize(event) ⇒ Hook
Returns a new instance of Hook.
16 17 18 |
# File 'app/models/tokite/hook.rb', line 16 def initialize(event) @event = event end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
3 4 5 |
# File 'app/models/tokite/hook.rb', line 3 def event @event end |
Class Method Details
.fire!(github_event, hook_params) ⇒ Object
11 12 13 14 |
# File 'app/models/tokite/hook.rb', line 11 def self.fire!(github_event, hook_params) event_class = HOOK_EVENTS[github_event] Hook.new(event_class.new(hook_params)).fire! if event_class end |
Instance Method Details
#fire! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/tokite/hook.rb', line 20 def fire! return unless event.notify? Rule.matched_rules(event).each do |rule| = event. [:fallback] += "\n\n#{rule.}" [:text] += "\n\n#{rule.}" emoji = rule.icon_emoji.chomp.presence additional_text = rule.additional_text notify!(channel: rule.channel, text: event.slack_text, icon_emoji: emoji, attachments: []) notify!(channel: rule.channel, text: additional_text, icon_emoji: emoji, parse: "full") if additional_text.present? end end |
#notify!(payload) ⇒ Object
34 35 36 |
# File 'app/models/tokite/hook.rb', line 34 def notify!(payload) NotifyGithubHookEventJob.perform_now(payload.compact) end |