-
Notifications
You must be signed in to change notification settings - Fork 143
Deploy notifications #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasonfine
wants to merge
10
commits into
master
Choose a base branch
from
deploy-notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Deploy notifications #606
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
622de77
squash commits
jasonfine 0eec300
check in
jasonfine de20fa7
some tests
jasonfine d4a8407
cruft
jasonfine c12d873
more testing
jasonfine 16abc5a
documentation
jasonfine bc92cc4
rm config from devise config that should not be there
jasonfine f50a2a4
log if request body is blank
jasonfine 4148050
rm unused gem, rm deploy_notifications_mailer_sender usage and refs; …
jasonfine e6a9f0c
update notification error text
jasonfine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -26,4 +26,6 @@ spec/dummy/public/uploads/* | |
|
|
||
| /vendor | ||
| docker-compose.override.yml | ||
| .env | ||
| .env | ||
| mysql | ||
| node_modules | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,6 +19,5 @@ def deploy_site | |
| end | ||
| render json: {success: false} | ||
| end | ||
|
|
||
| end | ||
| end | ||
This file contains hidden or 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,28 @@ | ||
| module Fae | ||
| class NetlifyHooksController < ActionController::Base | ||
|
|
||
| def netlify_hook | ||
| unless Rails.env.test? | ||
| signature = request.headers["X-Webhook-Signature"] | ||
| if signature.blank? | ||
| Rails.logger.info 'request.headers["X-Webhook-Signature"] header is missing' | ||
| return head :forbidden | ||
| end | ||
| if Fae.netlify[:notification_hook_signature].blank? | ||
| Rails.logger.info "Fae.netlify[:notification_hook_signature] is not set" | ||
| return head :forbidden | ||
| end | ||
|
|
||
| options = {iss: "netlify", verify_iss: true, algorithm: "HS256"} | ||
| decoded = JWT.decode(signature, Fae.netlify[:notification_hook_signature], true, options) | ||
| unless decoded.first['sha256'] == Digest::SHA256.hexdigest(request.body.read) | ||
| Rails.logger.info "Netlify hook signature mismatch, check the value of Fae.netlify[:notification_hook_signature] against the value of the JWS secret token in the Netlify webhook settings." | ||
| return head :forbidden | ||
| end | ||
| end | ||
|
|
||
| DeployNotifications.notify_admins(request.body.read).deliver_now | ||
| return head :ok | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 @@ | ||
| module Fae | ||
| class DeployNotifications < ActionMailer::Base | ||
| default from: Fae.deploy_notifications_mailer_sender | ||
| layout 'layouts/fae/mailer' | ||
|
|
||
| def notify_admins(body = nil, additional_emails = []) | ||
| if body.blank? | ||
| Rails.logger.info "DeployNotifications.notify_admins called without a body" | ||
| return | ||
| end | ||
| body = JSON.parse(body) | ||
|
|
||
| # Don't notify if the deploy is a code push | ||
| if body['commit_ref'].present? | ||
| Rails.logger.info "#{body['context']} - #{body['id']} is a code push, skipping notification" | ||
| Rails.logger.info "#{body['branch']} #{body['commit_ref']}: #{body['commit_message']}" | ||
| return | ||
| end | ||
|
|
||
| @deploy = body | ||
| recipients = Fae::User.where(receive_deploy_notifications: true).pluck(:email) | ||
| recipients += additional_emails | ||
| @fae_options = Fae::Option.instance | ||
| current_time_in_zone = Time.now.in_time_zone(@fae_options.time_zone).strftime('%Y-%m-%d %l:%M %p') | ||
| subject = "#{@fae_options.title} Deploy Notification #{current_time_in_zone}" | ||
| mail(to: recipients, subject: subject) | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 @@ | ||
| module Fae | ||
| class Deploy < ApplicationRecord | ||
| belongs_to :user | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,9 @@ | ||
| <% if @deploy['title'].present? %> | ||
| <%= @deploy['title'].gsub('+', ' ') %> | ||
| <% end %> | ||
|
|
||
| <% if @deploy['state'] == 'ready' %> | ||
| The deploy was successful. | ||
| <% else %> | ||
| An error occurred. Please contact your FINE team. | ||
|
jasonfine marked this conversation as resolved.
Outdated
|
||
| <% end %> | ||
This file contains hidden or 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 hidden or 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 @@ | ||
| = yield |
This file contains hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
db/migrate/20240220144206_add_receive_deploy_notifications_to_fae_users.rb
This file contains hidden or 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,6 @@ | ||
| class AddReceiveDeployNotificationsToFaeUsers < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :fae_users, :receive_deploy_notifications, :boolean, default: false | ||
| add_index :fae_users, :receive_deploy_notifications | ||
| end | ||
| end |
This file contains hidden or 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,13 @@ | ||
| class CreateFaeDeploys < ActiveRecord::Migration[7.0] | ||
| def change | ||
| create_table :fae_deploys do |t| | ||
| t.integer :user_id, index: true | ||
| t.string :environment | ||
| t.string :deploy_id, index: true | ||
| t.string :deploy_status | ||
| t.boolean :notified | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doc is a good foundations but I'm going to take a final pass at this before merging. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.