Skip to content

Instantly share code, notes, and snippets.

@bethesque
Last active November 26, 2018 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bethesque/3da19b11e9e5278e4d36 to your computer and use it in GitHub Desktop.
Save bethesque/3da19b11e9e5278e4d36 to your computer and use it in GitHub Desktop.
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