-
Notifications
You must be signed in to change notification settings - Fork 0
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 #20 from razeware/development
v1.0.1: 🐌 Mail
- Loading branch information
Showing
11 changed files
with
166 additions
and
20 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 |
---|---|---|
|
@@ -14,3 +14,6 @@ AWS_REGION= | |
|
||
# CDN for image uploads | ||
IMAGES_CDN_HOST= | ||
|
||
# Build notifications as part of CI | ||
SLACK_WEBHOOK_URL= |
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
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
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,119 @@ | ||
# frozen_string_literal: true | ||
|
||
module Util | ||
# Adds methods that allow slack notifications | ||
module SlackNotifiable # rubocop:disable Metrics/ModuleLength | ||
extend ActiveSupport::Concern | ||
|
||
SUCCESS_IMAGE_URL = 'https://wolverine.raywenderlich.com/v3-resources/razebot/images/object_textkit-book.png' | ||
FAILURE_IMAGE_URL = 'https://wolverine.raywenderlich.com/v3-resources/razebot/images/object_errors.png' | ||
ROBLES_CONTEXT_IMAGE_URL = 'https://wolverine.raywenderlich.com/v3-resources/razebot/images/object_box-of-books.png' | ||
|
||
def notify_success(book:) | ||
return unless notifiable? | ||
|
||
notifier.post(blocks: success_blocks(book: book)) | ||
end | ||
|
||
def notify_failure(book:, details: nil) | ||
return unless notifiable? | ||
|
||
notifier.post(blocks: failure_blocks(book: book, details: details || 'N/A')) | ||
end | ||
|
||
def notifiable? | ||
SLACK_WEBHOOK_URL.present? | ||
end | ||
|
||
def notifier | ||
@notifier ||= Slack::Notifier.new(SLACK_WEBHOOK_URL, channel: SLACK_CHANNEL, username: SLACK_USERNAME) | ||
end | ||
|
||
def success_blocks(book:) | ||
[ | ||
intro_section(book: book, | ||
message: ':white_check_mark: Book publication successful!', | ||
image_url: SUCCESS_IMAGE_URL, | ||
alt_text: 'Publication successful'), | ||
{ | ||
type: 'divider' | ||
}, | ||
context | ||
] | ||
end | ||
|
||
def failure_blocks(book:, details:) # rubocop:disable Metrics/MethodLength | ||
[ | ||
intro_section(book: book, | ||
message: ':x: Book publication failed!', | ||
image_url: FAILURE_IMAGE_URL, | ||
alt_text: 'Publication failed'), | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: "```#{details}```" | ||
} | ||
}, | ||
{ | ||
type: 'divider' | ||
}, | ||
context | ||
] | ||
end | ||
|
||
def standard_fields(book:) # rubocop:disable Metrics/MethodLength | ||
[ | ||
{ | ||
type: 'mrkdwn', | ||
text: "*Book*\n#{book&.title || '_unknown_'}" | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: "*SKU*\n`#{book&.sku || 'unknown'}`" | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: "*Edition*\n#{book&.edition || '_unknown_'}" | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: "*Environment*\n`#{ENVIRONMENT}`" | ||
} | ||
] | ||
end | ||
|
||
def intro_section(book:, message:, image_url:, alt_text:) # rubocop:disable Metrics/MethodLength | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: message | ||
}, | ||
fields: standard_fields(book: book), | ||
accessory: { | ||
type: 'image', | ||
image_url: image_url, | ||
alt_text: alt_text | ||
} | ||
} | ||
end | ||
|
||
def context # rubocop:disable Metrics/MethodLength | ||
{ | ||
type: 'context', | ||
elements: [ | ||
{ | ||
type: 'image', | ||
image_url: ROBLES_CONTEXT_IMAGE_URL, | ||
alt_text: 'robles via razebot' | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: 'This is a message sent from *robles* via *razebot*.' | ||
} | ||
] | ||
} | ||
end | ||
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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
ENVIRONMENT = ENV['ENV'] || 'development' |
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
SLACK_WEBHOOK_URL = ENV['SLACK_WEBHOOK_URL'] | ||
SLACK_CHANNEL = ENV['SLACK_CHANNEL'] || '#robles' | ||
SLACK_USERNAME = ENV['SLACK_USERNAME'] || 'razebot' |