Last active
November 26, 2018 00:53
-
-
Save bethesque/3da19b11e9e5278e4d36 to your computer and use it in GitHub Desktop.
Migrate pacts from one pact broker to another
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
# Note: this does not migrate the tags | |
require 'faraday' | |
require 'json' | |
source_host = 'http://some-pact-broker' | |
destination_host = 'http://localhost:9292' | |
latest_pacts_response = JSON.parse(Faraday.get("#{source_host}/pacts/latest").body) | |
pact_hrefs = latest_pacts_response['pacts'].collect{ | pact | pact['_links']['self'][1]['href'] } | |
pact_hrefs.each do | href | | |
pact = JSON.parse(Faraday.get(href).body) | |
pact.delete('_links') | |
pact.delete('_embedded') | |
pact.delete('createdAt') | |
pact.delete('updatedAt') | |
destination_href = href.gsub(source_host, destination_host) | |
puts "Moving #{href} to #{destination_href}" | |
Faraday.put(destination_href, pact.to_json, {'Content-Type' => 'application/json'}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment