-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from kortirso/issue_311
IS-311 modify notifiers structure
- Loading branch information
Showing
67 changed files
with
969 additions
and
1,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class AdminDelivery < ApplicationDelivery | ||
before_notify :ensure_mailer_enabled, on: :mailer | ||
before_notify :ensure_webhook_enabled, on: :webhook | ||
before_notify :ensure_slack_webhook_enabled, on: :slack_webhook | ||
before_notify :ensure_discord_webhook_enabled, on: :discord_webhook | ||
before_notify :ensure_slack_enabled, on: :slack | ||
before_notify :ensure_discord_enabled, on: :discord | ||
before_notify :ensure_telegram_enabled, on: :telegram | ||
|
||
delivers :job_execution_report | ||
delivers :feedback_created | ||
|
||
private | ||
|
||
def ensure_mailer_enabled = false | ||
def ensure_webhook_enabled = false | ||
def ensure_slack_webhook_enabled = false | ||
def ensure_discord_webhook_enabled = false | ||
def ensure_slack_enabled = false | ||
def ensure_discord_enabled = false | ||
def ensure_telegram_enabled = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class AdminTelegramNotifier < CompanyNotifier | ||
self.driver = proc do |data| | ||
Pullmetry::Container['api.telegram.client'].send_message( | ||
bot_secret: Rails.application.credentials.dig(:telegram_oauth, Rails.env.to_sym, :bot_secret), | ||
chat_id: data[:chat_id], | ||
text: data[:body] | ||
) | ||
end | ||
|
||
def job_execution_report | ||
notification( | ||
chat_id: Rails.application.credentials[:reports_telegram_chat_id], | ||
body: "#{params[:job_name]} is run at #{DateTime.now}" | ||
) | ||
end | ||
|
||
def feedback_created | ||
notification( | ||
chat_id: Rails.application.credentials[:reports_telegram_chat_id], | ||
body: feedback_created_payload(params[:id]) | ||
) | ||
end | ||
|
||
private | ||
|
||
def feedback_created_payload(id) | ||
feedback = Feedback.find_by(id: id) | ||
return '' unless feedback | ||
|
||
"User - #{feedback.user_id}\nFeedback created - #{feedback.title}\n#{feedback.description}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompanyDiscordNotifier < CompanyNotifier | ||
self.driver = proc do |data| | ||
Pullmetry::Container['api.discord.client'].send_message( | ||
path: data[:path], | ||
body: data[:body] | ||
) | ||
end | ||
|
||
def insights_report = report(Webhook::DISCORD) | ||
def repository_insights_report = report(Webhook::DISCORD) | ||
def long_time_review_report = report(Webhook::DISCORD) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompanyNotifier < AbstractNotifier::Base | ||
include Deps[company_payload: 'notifiers.payloads.company'] | ||
|
||
private | ||
|
||
def report(source) | ||
path = webhook_path(source) | ||
url = URI(path) | ||
|
||
notification( | ||
**company_payload.call( | ||
type: source, | ||
path: path, | ||
url: url, | ||
insightable: insightable, | ||
notification_name: notification_name | ||
) | ||
) | ||
end | ||
|
||
def insightable = params[:insightable] | ||
|
||
def webhook_path(source) | ||
webhook = insightable.all_webhooks.where(source: source).order(webhookable_type: :asc).first | ||
URI(webhook.url).path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompanySlackNotifier < CompanyNotifier | ||
self.driver = proc do |data| | ||
Pullmetry::Container['api.slack.client'].send_message( | ||
path: data[:path], | ||
body: data[:body] | ||
) | ||
end | ||
|
||
def insights_report = report(Webhook::SLACK) | ||
def repository_insights_report = report(Webhook::SLACK) | ||
def long_time_review_report = report(Webhook::SLACK) | ||
end |
6 changes: 5 additions & 1 deletion
6
app/notifiers/telegram_notifier.rb → app/notifiers/company_telegram_notifier.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class TelegramNotifier < AbstractNotifier::Base | ||
class CompanyTelegramNotifier < CompanyNotifier | ||
self.driver = proc do |data| | ||
Pullmetry::Container['api.telegram.client'].send_message( | ||
bot_secret: Rails.application.credentials.dig(:telegram_oauth, Rails.env.to_sym, :bot_secret), | ||
chat_id: data[:chat_id], | ||
text: data[:body] | ||
) | ||
end | ||
|
||
def insights_report = report(Webhook::TELEGRAM) | ||
def repository_insights_report = report(Webhook::TELEGRAM) | ||
def long_time_review_report = report(Webhook::TELEGRAM) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompanyWebhookNotifier < CompanyNotifier | ||
self.driver = proc do |data| | ||
url = URI(data[:path]) | ||
|
||
Webhooks::Client.new(url: url.origin).send_message( | ||
path: url.path, | ||
body: data[:body] | ||
) | ||
end | ||
|
||
def insights_report = report(Webhook::CUSTOM) | ||
def repository_insights_report = report(Webhook::CUSTOM) | ||
def long_time_review_report = report(Webhook::CUSTOM) | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
app/notifiers/discord_webhooks/company/insights_report_payload.rb
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
app/notifiers/discord_webhooks/company/long_time_review_report_payload.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.