Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Migrate pacts from one pact broker to another
# 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
You can’t perform that action at this time.