require 'pact_broker/client/tasks'

# see https://github.com/pact-foundation/pact_broker-client/blob/master/README.md
namespace :broker do
  PactBroker::Client::PublicationTask.new(:local) do |task|
    format_rake_task(
        task,
        'http://pact-broker.docker',
        'pact',
        'broker',
        'local'
    )
  end

  PactBroker::Client::PublicationTask.new(:jenkins_post_merge) do |task|
    format_rake_task(
        task,
        ENV.fetch('PACT_BROKER_BASE_URL'),
        ENV.fetch('PACT_BROKER_BASIC_AUTH_USERNAME'),
        ENV.fetch('PACT_BROKER_BASIC_AUTH_PASSWORD'),
        'master'
    )
  end

  def format_rake_task(task, url, username, password, task_tag)
    require 'quiz_api_client'

    task.consumer_version = CanvasApiClient::VERSION
    task.pattern = 'pacts/*.json'

    task.pact_broker_base_url = url
    task.pact_broker_basic_auth = { username: username, password: password }

    task.tag = task_tag
    puts "Pact file tagged with: #{task.tag}"
  end
end

require 'pact_broker/client/tasks'

# see https://github.com/pact-foundation/pact_broker-client/blob/master/README.md
namespace :broker do
  PactBroker::Client::PublicationTask.new(:local) do |task|
    format_rake_task(
        task,
        'http://pact-broker.docker',
        'pact',
        'broker',
        'local'
    )
  end

  PactBroker::Client::PublicationTask.new(:jenkins_post_merge) do |task|
    format_rake_task(
        task,
        ENV.fetch('PACT_BROKER_HOST'),
        ENV.fetch('PACT_BROKER_USERNAME'),
        ENV.fetch('PACT_BROKER_PASSWORD'),
        'master'
    )
  end

  def format_rake_task(task, url, username, password, task_tag)
    task.consumer_version = CanvasApiClient::VERSION
    task.pattern = 'pacts/*.json'

    task.pact_broker_base_url = url
    task.pact_broker_basic_auth = { username: username, password: password }

    task.tag = task_tag
    puts "Pact file tagged with: #{task.tag}"
  end
end

Modify cnvas_rake file for pact
spec: Modify cnvas_rake file for pact

Test Plan:
  -- Passes Jenkins

Change-Id: I55c8cc6d0a742afd330e54c6c1c74d08cd6332ef
Reviewed-on: https://gerrit.instructure.com/153898
Reviewed-by: Anju Reddy <851202533fb1f0b615e4547ba226c76996d060dd@instructure.com>
Tested-by: Jenkins
Product-Review: Deepeeca Soundarrajan <5bcd4b623f00b7fc2942cd1c65c245b30a48a61f@instructure.com>
QA-Review: Deepeeca Soundarrajan <5bcd4b623f00b7fc2942cd1c65c245b30a48a61f@instructure.com>
