Skip to content

Instantly share code, notes, and snippets.

@unlox775
Created August 29, 2025 17:25
Show Gist options
  • Select an option

  • Save unlox775/109e1e776e8a72a5d2635a1e980a0912 to your computer and use it in GitHub Desktop.

Select an option

Save unlox775/109e1e776e8a72a5d2635a1e980a0912 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
# Function to extract hostnames by actually loading the Ruby module
def extract_hostnames_from_module(file_path)
# Read the file content
content = File.read(file_path)
# Create a temporary module to load the content
module_content = content.gsub(/module AllowedHostnameHelper/, 'module TempAllowedHostnameHelper')
# Write to a temporary file
temp_file = '/tmp/temp_allowed_hostname_helper.rb'
File.write(temp_file, module_content)
# Load the temporary module
load temp_file
# Access the constant
hostnames = TempAllowedHostnameHelper::ALLOWED_HOSTNAME_SUFFIXES
# Clean up
File.delete(temp_file)
return hostnames.sort
rescue => e
puts "Error loading module: #{e.message}"
return []
end
# Get current version
current_file = 'dashboard/app/helpers/allowed_hostname_helper.rb'
current_hostnames = extract_hostnames_from_module(current_file)
# Get previous version from git
previous_content = `git show HEAD~1:#{current_file}`
temp_previous_file = '/tmp/previous_allowed_hostname_helper.rb'
File.write(temp_previous_file, previous_content)
previous_hostnames = extract_hostnames_from_module(temp_previous_file)
File.delete(temp_previous_file)
# Write both lists to files
File.write('/tmp/current_hostnames.txt', current_hostnames.join("\n"))
File.write('/tmp/previous_hostnames.txt', previous_hostnames.join("\n"))
# Compare and show differences
puts "=== CURRENT HOSTNAMES (#{current_hostnames.length}) ==="
puts current_hostnames.join("\n")
puts "\n"
puts "=== PREVIOUS HOSTNAMES (#{previous_hostnames.length}) ==="
puts previous_hostnames.join("\n")
puts "\n"
puts "=== COMPARISON ==="
missing = previous_hostnames - current_hostnames
added = current_hostnames - previous_hostnames
if missing.any?
puts "MISSING from current version:"
missing.each { |h| puts " - #{h}" }
puts
end
if added.any?
puts "ADDED in current version:"
added.each { |h| puts " + #{h}" }
puts
end
if missing.empty? && added.empty?
puts "✅ All hostnames are present - no differences found!"
else
puts "❌ Differences found - check the lists above"
end
puts "\nFiles written to:"
puts " /tmp/current_hostnames.txt"
puts " /tmp/previous_hostnames.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment