Last active
March 26, 2019 00:01
-
-
Save gfu-clutter/4c8d1764922ceba9a97962810ebd7f2b to your computer and use it in GitHub Desktop.
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
namespace :heroku do | |
desc 'Delete teh custom domain record set up for the Review App' | |
task :review_app_predestroy do | |
require 'dnsimple' | |
# Cleanup subdomain DNS record for Heroku review app | |
clutter_domain = 'clutter.com'.freeze | |
heroku_app_name = ENV['HEROKU_APP_NAME'] | |
dnsimple_account_id = ENV['DNSIMPLE_ACCOUNT_ID'] | |
# Extract out "pr-<pull request ID>" from default name | |
pr_number = heroku_app_name.match(/.*(pr-\d+)/).captures.first | |
subdomain = "account-#{pr_number}" | |
dnsimple_client = Dnsimple::Client.new access_token: ENV['DNSIMPLE_ACCESS_TOKEN'] | |
# Remove record from DNSimple | |
resp = dnsimple_client.zones.zone_records dnsimple_account_id, clutter_domain, { filter: { name_like: subdomain } } | |
if resp.total_entries == 1 | |
record_id = resp.data[0].id | |
dnsimple_client.zones.delete_zone_record dnsimple_account_id, clutter_domain, record_id | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment