-
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.
- Loading branch information
Showing
41 changed files
with
444 additions
and
521 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
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,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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompanyNotifier < AbstractNotifier::Base | ||
private | ||
|
||
def report(source) | ||
path = webhook_path(source) | ||
url = URI(path) | ||
|
||
notification( | ||
**Payloads::Company.new.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 CompanyDiscordNotifier < 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.
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
module Payloads | ||
class Company | ||
def call(type:, path:, url:, insightable:, notification_name:) | ||
case type | ||
when Notification::TELEGRAM then telegram_payload(path, insightable, notification_name) | ||
when Notification::DISCORD then discord_payload(path, insightable, notification_name) | ||
when Notification::SLACK then slack_payload(path, insightable, notification_name) | ||
when Notification::CUSTOM then custom_payload(url.path, insightable, notification_name) | ||
end | ||
end | ||
|
||
private | ||
|
||
def telegram_payload(path, insightable, notification_name) | ||
{ | ||
chat_id: path, | ||
body: telegram_report(insightable, notification_name) | ||
} | ||
end | ||
|
||
def telegram_report(insightable, notification_name) | ||
case notification_name | ||
when :insights_report then Reports::Company::Telegram::Insights.new.call(insightable: insightable) | ||
end | ||
end | ||
|
||
def discord_payload(path, insightable, notification_name) | ||
{ | ||
path: path, | ||
body: { | ||
username: 'PullKeeper', | ||
content: discord_report(insightable, notification_name) | ||
} | ||
} | ||
end | ||
|
||
def discord_report(insightable, notification_name) | ||
case notification_name | ||
when :insights_report then Reports::Company::Discord::Insights.new.call(insightable: insightable) | ||
end | ||
end | ||
|
||
def slack_payload(path, insightable, notification_name) | ||
{ | ||
path: path, | ||
body: slack_report(insightable, notification_name) | ||
} | ||
end | ||
|
||
def slack_report(insightable, notification_name) | ||
case notification_name | ||
when :insights_report then Reports::Company::Slack::Insights.new.call(insightable: insightable) | ||
end | ||
end | ||
|
||
def custom_payload(path, insightable, notification_name) | ||
{ | ||
path: path, | ||
body: { | ||
content: custom_report(insightable, notification_name) | ||
} | ||
} | ||
end | ||
|
||
def custom_report(insightable, notification_name) | ||
case notification_name | ||
when :insights_report then Reports::Company::Custom::Insights.new.call(insightable: insightable) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.