-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-version-tag): add CLI to tag a pacticipant version
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'pact_broker/client/error' | ||
require 'pact_broker/client/pact_broker_client' | ||
require 'pact_broker/client/retry' | ||
|
||
module PactBroker | ||
module Client | ||
class CreateTag | ||
|
||
class Result | ||
attr_reader :success, :message | ||
|
||
def initialize success, message = nil | ||
@success = success | ||
@message = message | ||
end | ||
end | ||
|
||
def self.call(pact_broker_base_url, pacticipant_name, version, tags, pact_broker_client_options={}) | ||
new(pact_broker_base_url, pacticipant_name, version, tags, pact_broker_client_options).call | ||
end | ||
|
||
def initialize(pact_broker_base_url, pacticipant_name, version, tags, pact_broker_client_options) | ||
@pact_broker_base_url = pact_broker_base_url | ||
@pacticipant_name = pacticipant_name | ||
@version = version | ||
@tags = tags | ||
@pact_broker_client_options = pact_broker_client_options | ||
end | ||
|
||
def call | ||
tags.each do | tag | | ||
# todo check that pacticipant exists first | ||
$stdout.puts "Tagging #{pacticipant_name} version #{version} as #{tag}" | ||
Retry.until_true do | ||
pact_broker_client.pacticipants.versions.tag pacticipant: pacticipant_name, version: version, tag: tag | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :pact_broker_base_url, :pacticipant_name, :version, :tags, :pact_broker_client_options | ||
|
||
def pact_broker_client | ||
@pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe "pact-broker create-version-tag" do | ||
before(:all) do | ||
@pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5001") | ||
sleep 2 | ||
end | ||
|
||
context "when the version is successfully tagged" do | ||
subject { `bundle exec bin/pact-broker create-version-tag -v --pacticipant Condor --version 1.3.0 --tag prod --broker-base-url http://localhost:5001` } | ||
|
||
it "returns a success exit code" do | ||
subject | ||
expect($?.exitstatus).to eq 0 | ||
expect(subject).to include 'Tagging Condor version 1.3.0 as prod' | ||
end | ||
end | ||
|
||
after(:all) do | ||
Process.kill 'KILL', @pipe.pid | ||
end | ||
end |