pact_broker-client 1.73.0 → 1.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release_gem.yml +2 -2
  3. data/.github/workflows/test.yml +4 -1
  4. data/.github/workflows/trigger_pact_docs_update.yml +1 -1
  5. data/CHANGELOG.md +22 -0
  6. data/Gemfile +1 -0
  7. data/README.md +100 -35
  8. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +45 -0
  9. data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +1 -1
  10. data/example/scripts/publish-pact-rake.sh +10 -0
  11. data/example/scripts/publish-pact.sh +25 -1
  12. data/example/scripts/publish-provider-contract.sh +2 -1
  13. data/lib/pact_broker/client/branches/delete_branch.rb +64 -0
  14. data/lib/pact_broker/client/cli/branch_commands.rb +40 -0
  15. data/lib/pact_broker/client/cli/broker.rb +2 -1
  16. data/lib/pact_broker/client/cli/custom_thor.rb +2 -2
  17. data/lib/pact_broker/client/cli/environment_commands.rb +1 -1
  18. data/lib/pact_broker/client/cli/pact_commands.rb +35 -14
  19. data/lib/pact_broker/client/cli/version_commands.rb +2 -2
  20. data/lib/pact_broker/client/git.rb +20 -3
  21. data/lib/pact_broker/client/merge_pacts.rb +5 -2
  22. data/lib/pact_broker/client/publish_pacts_the_old_way.rb +1 -1
  23. data/lib/pact_broker/client/tasks/publication_task.rb +40 -23
  24. data/lib/pact_broker/client/version.rb +1 -1
  25. data/lib/pactflow/client/cli/provider_contract_commands.rb +1 -1
  26. data/lib/pactflow/client/provider_contracts/publish.rb +1 -1
  27. data/script/publish-provider-contract.sh +0 -1
  28. data/script/update-cli-usage-in-readme.rb +1 -0
  29. data/spec/fixtures/MyConsumer-MyProvider (1).json +37 -0
  30. data/spec/fixtures/MyConsumer-MyProvider.json +37 -0
  31. data/spec/integration/can_i_deploy_spec.rb +0 -9
  32. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +103 -0
  33. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +38 -21
  34. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +26 -0
  35. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +1 -3
  36. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +54 -31
  37. data/spec/pacts/pact_broker_client-pact_broker.json +43 -0
  38. data/spec/pacts/pact_broker_client-pactflow.json +1 -1
  39. data/spec/service_providers/delete_branch_spec.rb +68 -0
  40. data/spec/service_providers/pact_helper.rb +1 -0
  41. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +1 -1
  42. data/spec/support/ssl_server.rb +1 -1
  43. data/tasks/pact.rake +79 -0
  44. metadata +14 -3
@@ -0,0 +1,40 @@
1
+ module PactBroker
2
+ module Client
3
+ module CLI
4
+ module BranchCommands
5
+ def self.included(thor)
6
+ thor.class_eval do
7
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that the branch belongs to."
8
+ method_option :branch, required: true, desc: "The pacticipant branch name."
9
+ method_option :error_when_not_found, type: :boolean, default: true, desc: "Raise an error if the branch that is to be deleted is not found."
10
+ shared_authentication_options
11
+
12
+ desc "delete-branch", "Deletes a pacticipant branch. Does not delete the versions or pacts/verifications associated with the branch, but does make the pacts inaccessible for verification via consumer versions selectors or WIP pacts."
13
+
14
+ def delete_branch
15
+ require "pact_broker/client/branches/delete_branch"
16
+
17
+ validate_credentials
18
+ params = {
19
+ pacticipant: options.pacticipant,
20
+ branch: options.branch,
21
+ error_when_not_found: options.error_when_not_found
22
+ }
23
+
24
+ result = PactBroker::Client::Branches::DeleteBranch.call(params, {}, pact_broker_client_options)
25
+ $stdout.puts result.message
26
+ exit(1) unless result.success
27
+ end
28
+
29
+ no_commands do
30
+ def validate_delete_branch_params
31
+ raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.pacticipant.strip.size == 0
32
+ raise ::Thor::RequiredArgumentMissingError, "Pacticipant branch name cannot be blank" if options.branch.strip.size == 0
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -8,7 +8,7 @@ require "pact_broker/client/cli/pacticipant_commands"
8
8
  require "pact_broker/client/cli/version_commands"
9
9
  require "pact_broker/client/cli/webhook_commands"
10
10
  require "pact_broker/client/cli/matrix_commands"
11
-
11
+ require "pact_broker/client/cli/branch_commands"
12
12
  module PactBroker
13
13
  module Client
14
14
  module CLI
@@ -19,6 +19,7 @@ module PactBroker
19
19
  include PactBroker::Client::CLI::MatrixCommands
20
20
  include PactBroker::Client::CLI::PacticipantCommands
21
21
  include PactBroker::Client::CLI::VersionCommands
22
+ include PactBroker::Client::CLI::BranchCommands
22
23
  include PactBroker::Client::CLI::WebhookCommands
23
24
 
24
25
  ignored_and_hidden_potential_options_from_environment_variables
@@ -126,11 +126,11 @@ module PactBroker
126
126
  method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
127
127
  method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
128
128
  method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
129
- method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
129
+ method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output."
130
130
  end
131
131
 
132
132
  def self.verbose_option
133
- method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
133
+ method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output."
134
134
  end
135
135
 
136
136
  def self.output_option_json_or_text
@@ -9,7 +9,7 @@ module PactBroker
9
9
  def self.shared_environment_options(name_required: false)
10
10
  method_option :name, required: name_required, desc: "The uniquely identifying name of the environment as used in deployment code"
11
11
  method_option :display_name, desc: "The display name of the environment"
12
- method_option :production, type: :boolean, default: false, desc: "Whether or not this environment is a production environment. This is currently informational only. Default: false"
12
+ method_option :production, type: :boolean, default: false, desc: "Whether or not this environment is a production environment. This is currently informational only."
13
13
  method_option :contact_name, required: false, desc: "The name of the team/person responsible for this environment"
14
14
  method_option :contact_email_address, required: false, desc: "The email address of the team/person responsible for this environment"
15
15
  output_option_json_or_text
@@ -1,4 +1,5 @@
1
1
  require "pact_broker/client/hash_refinements"
2
+ require 'pact_broker/client/string_refinements'
2
3
 
3
4
  module PactBroker
4
5
  module Client
@@ -8,23 +9,26 @@ module PactBroker
8
9
 
9
10
  module PactCommands
10
11
  using PactBroker::Client::HashRefinements
12
+ using PactBroker::Client::StringRefinements
11
13
 
12
14
  def self.included(thor)
13
15
  thor.class_eval do
14
16
  desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
15
- method_option :consumer_app_version, required: true, aliases: "-a", desc: "The consumer application version"
17
+ method_option :consumer_app_version, aliases: "-a", desc: "The consumer application version"
16
18
  method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
17
- method_option :auto_detect_version_properties, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
19
+ method_option :auto_detect_version_properties, aliases: "-r", type: :boolean, default: false, desc: "Automatically detect the repository commit, branch and build URL from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
18
20
  method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
19
- method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps. Default: false"
21
+ method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
20
22
  method_option :build_url, desc: "The build URL that created the pact"
21
23
  method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
22
24
  output_option_json_or_text
23
25
  shared_authentication_options
24
26
 
25
27
  def publish(*pact_files)
26
- require 'pact_broker/client/error'
28
+ require "pact_broker/client/error"
29
+ require "pact_broker/client/git"
27
30
  validate_credentials
31
+ validate_consumer_version
28
32
  validate_pact_files(pact_files)
29
33
  result = publish_pacts(pact_files)
30
34
  $stdout.puts result.message
@@ -50,17 +54,21 @@ module PactBroker
50
54
  end
51
55
  end
52
56
 
57
+ def validate_consumer_version
58
+ if consumer_app_version.blank?
59
+ raise ::Thor::RequiredArgumentMissingError, "No value provided for required option --consumer-app-version"
60
+ end
61
+ end
53
62
 
54
63
  def publish_pacts pact_files
55
64
  require 'pact_broker/client/publish_pacts'
56
65
 
57
66
  write_options = options[:merge] ? { write: :merge } : {}
58
67
  consumer_version_params = {
59
- number: options.consumer_app_version,
68
+ number: consumer_app_version,
60
69
  branch: branch,
61
70
  tags: tags,
62
- build_url: options.build_url,
63
- version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
71
+ build_url: build_url
64
72
  }.compact
65
73
 
66
74
  PactBroker::Client::PublishPacts.call(
@@ -99,25 +107,38 @@ module PactBroker
99
107
  end
100
108
 
101
109
  def tags
102
- require 'pact_broker/client/git'
103
-
104
110
  t = [*options.tag]
105
111
  t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
106
112
  t.compact.uniq
107
113
  end
108
114
 
109
115
  def branch
110
- require 'pact_broker/client/git'
111
-
112
116
  if options.branch.nil? && options.auto_detect_version_properties
113
- PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties)
117
+ PactBroker::Client::Git.branch(raise_error: true)
114
118
  else
115
119
  options.branch
116
120
  end
117
121
  end
118
122
 
119
- def explict_auto_detect_version_properties
120
- @explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties")
123
+ def consumer_app_version
124
+ if defined?(@consumer_app_version)
125
+ @consumer_app_version
126
+ else
127
+ @consumer_app_version = if options.consumer_app_version.blank? && options.auto_detect_version_properties
128
+ PactBroker::Client::Git.commit(raise_error: true)
129
+ else
130
+ options.consumer_app_version
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ def build_url
137
+ if options.build_url.blank? && options.auto_detect_version_properties
138
+ PactBroker::Client::Git.build_url
139
+ else
140
+ options.build_url
141
+ end
121
142
  end
122
143
  end
123
144
  end
@@ -59,8 +59,8 @@ module PactBroker
59
59
  method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
60
60
  method_option :version, required: true, aliases: "-e", desc: "The pacticipant version"
61
61
  method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
62
- method_option :auto_create_version, type: :boolean, default: false, desc: "Automatically create the pacticipant version if it does not exist. Default: false"
63
- method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag pacticipant version with the name of the current git branch. Default: false"
62
+ method_option :auto_create_version, type: :boolean, default: false, desc: "Automatically create the pacticipant version if it does not exist."
63
+ method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag pacticipant version with the name of the current git branch."
64
64
  shared_authentication_options
65
65
 
66
66
  def create_version_tag
@@ -2,7 +2,6 @@ require 'pact_broker/client/error'
2
2
  require 'pact_broker/client/hash_refinements'
3
3
 
4
4
  =begin
5
-
6
5
  BUILDKITE_BRANCH BUILDKITE_COMMIT https://buildkite.com/docs/pipelines/environment-variables
7
6
  CIRCLE_BRANCH CIRCLE_SHA1 https://circleci.com/docs/2.0/env-vars/
8
7
  TRAVIS_COMMIT TRAVIS_BRANCH - TRAVIS_PULL_REQUEST_BRANCH TRAVIS_PULL_REQUEST_SHA https://docs.travis-ci.com/user/environment-variables/
@@ -26,18 +25,21 @@ module PactBroker
26
25
  using PactBroker::Client::HashRefinements
27
26
 
28
27
  COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
28
+ COMMIT_COMMAND = 'git rev-parse HEAD'.freeze
29
29
  BRANCH_ENV_VAR_NAMES = %w{GITHUB_HEAD_REF GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH BUILD_SOURCEBRANCHNAME CIRRUS_BRANCH}.freeze
30
30
  COMMIT_ENV_VAR_NAMES = %w{GITHUB_SHA BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT BUILD_SOURCEVERSION CIRRUS_CHANGE_IN_REPO}
31
31
  BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
32
32
 
33
- def self.commit
34
- find_commit_from_env_vars
33
+ def self.commit(options)
34
+ find_commit_from_env_vars || commit_from_git_command(options[:raise_error])
35
35
  end
36
36
 
37
37
  def self.branch(options)
38
38
  find_branch_from_known_env_vars || find_branch_from_env_var_ending_with_branch || branch_from_git_command(options[:raise_error])
39
39
  end
40
40
 
41
+ # This does not belong in the Git module.
42
+ # TODO move it.
41
43
  def self.build_url
42
44
  github_build_url || BUILD_URL_ENV_VAR_NAMES.collect{ | name | value_from_env_var(name) }.compact.first
43
45
  end
@@ -79,6 +81,10 @@ module PactBroker
79
81
  branch_names.size == 1 ? branch_names[0] : nil
80
82
  end
81
83
 
84
+ def self.commit_from_git_command(raise_error)
85
+ execute_git_commit_command(raise_error)
86
+ end
87
+
82
88
  def self.validate_branch_names(branch_names)
83
89
  if branch_names.size == 0
84
90
  raise PactBroker::Client::Error, "Command `#{COMMAND}` didn't return anything that could be identified as the current branch."
@@ -93,6 +99,17 @@ module PactBroker
93
99
  `#{COMMAND}`
94
100
  end
95
101
 
102
+ def self.execute_git_commit_command(raise_error)
103
+ `#{COMMIT_COMMAND}`
104
+ rescue StandardError => e
105
+ if raise_error
106
+ raise PactBroker::Client::Error,
107
+ "Could not determine current git commit using command `#{COMMIT_COMMAND}`. #{e.class} #{e.message}"
108
+ else
109
+ return nil
110
+ end
111
+ end
112
+
96
113
  def self.execute_and_parse_command(raise_error)
97
114
  execute_git_command
98
115
  .split("\n")
@@ -53,14 +53,17 @@ module PactBroker
53
53
  end
54
54
 
55
55
  def almost_duplicate_message(original, new_interaction)
56
- "Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{new_interaction[:providerState].inspect}) but a different request or response. " +
56
+ "Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{(new_interaction[:providerState] || new_interaction[:providerStates]).inspect}) but a different request or response. " +
57
57
  "Please use a different description or provider state, or hard-code any random data.\n\n" +
58
58
  original.to_json + "\n\n" + new_interaction.to_json
59
59
  end
60
60
 
61
61
  def same_description_and_state? original, additional
62
62
  original[:description] == additional[:description] &&
63
- original[:providerState] == additional[:providerState]
63
+ (
64
+ (original[:providerState] && original[:providerState] == additional[:providerState]) ||
65
+ (original[:providerStates] && original[:providerStates] == additional[:providerStates])
66
+ )
64
67
  end
65
68
  end
66
69
  end
@@ -42,7 +42,7 @@ module PactBroker
42
42
 
43
43
  private
44
44
 
45
- attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options, :version_required
45
+ attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options
46
46
 
47
47
  def pact_broker_client
48
48
  @pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
@@ -1,6 +1,8 @@
1
1
  require 'rake/tasklib'
2
2
  require 'pact_broker/client/git'
3
3
  require 'pact_broker/client/hash_refinements'
4
+ require 'pact_broker/client/string_refinements'
5
+ require "pact_broker/client/error"
4
6
 
5
7
  =begin
6
8
  require pact_broker/client/tasks
@@ -19,57 +21,52 @@ module PactBroker
19
21
  module Client
20
22
  class PublicationTask < ::Rake::TaskLib
21
23
  using PactBroker::Client::HashRefinements
24
+ using PactBroker::Client::StringRefinements
22
25
 
23
- attr_accessor :pattern, :pact_broker_base_url, :consumer_version, :tag, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token
24
- attr_reader :auto_detect_version_properties, :branch, :build_url
26
+ attr_accessor :pattern, :pact_broker_base_url, :tag, :build_url, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token
27
+ attr_reader :auto_detect_version_properties, :build_url
28
+ attr_writer :consumer_version, :branch
25
29
  alias_method :tags=, :tag=
26
30
  alias_method :tags, :tag
27
31
 
28
32
  def initialize name = nil, &block
29
33
  @name = name
30
34
  @auto_detect_version_properties = nil
31
- @version_required = false
32
35
  @pattern = 'spec/pacts/*.json'
33
36
  @pact_broker_base_url = 'http://pact-broker'
34
37
  rake_task &block
35
38
  end
36
39
 
37
40
  def auto_detect_version_properties= auto_detect_version_properties
38
- @version_required = version_required || auto_detect_version_properties
39
41
  @auto_detect_version_properties = auto_detect_version_properties
40
42
  end
41
-
42
- def branch= branch
43
- @version_required = version_required || !!branch
44
- @branch = branch
45
- end
46
-
47
- def build_url= build_url
48
- @version_required = version_required || !!build_url
49
- @build_url = build_url
50
- end
51
-
43
+
52
44
  private
53
45
 
54
- attr_reader :version_required
55
-
56
46
  def rake_task &block
57
47
  namespace :pact do
58
48
  desc "Publish pacts to pact broker"
59
49
  task task_name do
60
50
  block.call(self)
51
+ validate!
61
52
  require 'pact_broker/client/publish_pacts'
62
53
  pact_broker_client_options = { write: write_method, token: pact_broker_token }
63
54
  pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any?
64
55
  pact_broker_client_options.compact!
65
- consumer_version_params = { number: consumer_version, branch: the_branch, build_url: build_url, tags: all_tags, version_required: version_required }.compact
56
+ consumer_version_params = { number: consumer_version, branch: branch, build_url: build_url, tags: all_tags }.compact
66
57
  result = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version_params, {}, pact_broker_client_options).call
67
58
  $stdout.puts result.message
68
- raise "One or more pacts failed to be published" unless result.success
59
+ raise PactBroker::Client::Error.new("One or more pacts failed to be published") unless result.success
69
60
  end
70
61
  end
71
62
  end
72
63
 
64
+ def validate!
65
+ if consumer_version.blank?
66
+ raise PactBroker::Client::Error.new("A consumer version must be provided")
67
+ end
68
+ end
69
+
73
70
  def task_name
74
71
  @name ? "publish:#{@name}" : "publish"
75
72
  end
@@ -80,11 +77,31 @@ module PactBroker
80
77
  t.compact.uniq
81
78
  end
82
79
 
83
- def the_branch
84
- if branch.nil? && auto_detect_version_properties != false
85
- PactBroker::Client::Git.branch(raise_error: auto_detect_version_properties == true)
80
+ # Attempt to detect the branch automatically, but don't raise an error if the branch can't be found
81
+ # unless the user has explicitly enabled auto_detect_version_properties.
82
+ # This approach is an attempt to include the branch without the user having to explicitly
83
+ # set it, because people tend to not update things.
84
+ def branch
85
+ if @branch.nil? && auto_detect_version_properties != false
86
+ @branch = PactBroker::Client::Git.branch(raise_error: auto_detect_version_properties == true)
87
+ else
88
+ @branch
89
+ end
90
+ end
91
+
92
+ def consumer_version
93
+ if @consumer_version.nil? && @auto_detect_version_properties
94
+ @consumer_version = PactBroker::Client::Git.commit(raise_error: true)
95
+ else
96
+ @consumer_version
97
+ end
98
+ end
99
+
100
+ def build_url
101
+ if @build_url.nil? && @auto_detect_version_properties
102
+ @build_url = PactBroker::Client::Git.build_url
86
103
  else
87
- branch
104
+ @build_url
88
105
  end
89
106
  end
90
107
  end
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.73.0'
3
+ VERSION = '1.75.0'
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@ module Pactflow
16
16
  method_option :branch, aliases: "-h", desc: "Repository branch of the provider version"
17
17
  #method_option :auto_detect_version_properties, hidden: true, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI."
18
18
  method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for provider version. Can be specified multiple times."
19
- #method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
19
+ #method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch."
20
20
  method_option :specification, default: "oas", desc: "The contract specification"
21
21
  method_option :content_type, desc: "The content type. eg. application/yml"
22
22
  method_option :verification_success, type: :boolean, desc: "Whether or not the self verification passed successfully."
@@ -39,7 +39,7 @@ module Pactflow
39
39
  end
40
40
 
41
41
  def publish_provider_contracts
42
- @response_entity = index_resource._link(PUBLISH_RELATION).expand(provider: provider_name).post!(contract_params, headers: { "Accept" => "application/hal+json,application/problem+json" })
42
+ @response_entity = index_resource._link(PUBLISH_RELATION).expand(provider: provider_name).post!(contract_params, { "Accept" => "application/hal+json,application/problem+json" })
43
43
  end
44
44
 
45
45
  def contract_params
@@ -6,7 +6,6 @@ bundle exec bin/pactflow publish-provider-contract \
6
6
  --branch main \
7
7
  --tag dev \
8
8
  --specification oas \
9
- --content-type application/yml \
10
9
  --verification-exit-code 0 \
11
10
  --verification-results script/verification-results.txt \
12
11
  --verification-results-content-type text/plain \
@@ -23,6 +23,7 @@ PACT_BROKER_COMMAND_GROUPS = [
23
23
  [PactBroker::Client::CLI::Broker, "Matrix", %w[can-i-deploy can-i-merge]],
24
24
  [PactBroker::Client::CLI::Broker, "Pacticipants", %w[create-or-update-pacticipant describe-pacticipant list-pacticipants]],
25
25
  [PactBroker::Client::CLI::Broker, "Webhooks", %w[create-webhook create-or-update-webhook test-webhook]],
26
+ [PactBroker::Client::CLI::Broker, "Branches", %w[delete-branch]],
26
27
  [PactBroker::Client::CLI::Broker, "Tags", %w[create-version-tag]],
27
28
  [PactBroker::Client::CLI::Broker, "Versions", %w[describe-version create-or-update-version]],
28
29
  [PactBroker::Client::CLI::Broker, "Miscellaneous", %w[generate-uuid]]
@@ -0,0 +1,37 @@
1
+ {
2
+ "consumer": {
3
+ "name": "MyConsumer"
4
+ },
5
+ "interactions": [
6
+ {
7
+ "description": "request",
8
+ "providerStates": [
9
+ {
10
+ "name": "state 2"
11
+ }
12
+ ],
13
+ "request": {
14
+ "method": "GET",
15
+ "path": "/2"
16
+ },
17
+ "response": {
18
+ "status": 200
19
+ }
20
+ }
21
+ ],
22
+ "metadata": {
23
+ "pact-js": {
24
+ "version": "11.0.2"
25
+ },
26
+ "pactRust": {
27
+ "ffi": "0.4.0",
28
+ "models": "1.0.4"
29
+ },
30
+ "pactSpecification": {
31
+ "version": "3.0.0"
32
+ }
33
+ },
34
+ "provider": {
35
+ "name": "MyProvider"
36
+ }
37
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "consumer": {
3
+ "name": "MyConsumer"
4
+ },
5
+ "interactions": [
6
+ {
7
+ "description": "request",
8
+ "providerStates": [
9
+ {
10
+ "name": "state 1"
11
+ }
12
+ ],
13
+ "request": {
14
+ "method": "GET",
15
+ "path": "/1"
16
+ },
17
+ "response": {
18
+ "status": 200
19
+ }
20
+ }
21
+ ],
22
+ "metadata": {
23
+ "pact-js": {
24
+ "version": "11.0.2"
25
+ },
26
+ "pactRust": {
27
+ "ffi": "0.4.0",
28
+ "models": "1.0.4"
29
+ },
30
+ "pactSpecification": {
31
+ "version": "3.0.0"
32
+ }
33
+ },
34
+ "provider": {
35
+ "name": "MyProvider"
36
+ }
37
+ }
@@ -18,15 +18,6 @@ describe "pact-broker can-i-deploy", skip_windows: true do
18
18
  end
19
19
  end
20
20
 
21
- context "when the pacticipants can't be deployed" do
22
- subject { `bundle exec bin/pact-broker can-i-deploy --pacticipant Wiffle --version 1.2.3 --pacticipant Meep --version 4.5.6 --broker-base-url http://localhost:5000` }
23
-
24
- it "returns an error exit code" do
25
- subject
26
- expect($?.exitstatus).to_not eq 0
27
- end
28
- end
29
-
30
21
  after(:all) do
31
22
  Process.kill 'KILL', @pipe.pid
32
23
  end
@@ -0,0 +1,103 @@
1
+ require "pact_broker/client/branches/delete_branch"
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Branches
6
+ describe DeleteBranch do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) do
13
+ {
14
+ pacticipant: "Foo",
15
+ branch: "main",
16
+ error_when_not_found: error_when_not_found
17
+ }
18
+ end
19
+ let(:options) do
20
+ {
21
+ verbose: verbose
22
+ }
23
+ end
24
+ let(:error_when_not_found) { true }
25
+ let(:pact_broker_base_url) { "http://example.org" }
26
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
27
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
28
+ let(:verbose) { false }
29
+
30
+ before do
31
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
32
+ stub_request(:delete, "http://example.org/pacticipants/Foo/branches/main").to_return(status: delete_response_status, body: delete_response_body, headers: response_headers)
33
+ end
34
+ let(:delete_response_status) { 200 }
35
+
36
+ let(:index_response_body) do
37
+ {
38
+ "_links" => {
39
+ "pb:pacticipant-branch" => {
40
+ "href" => "http://example.org/pacticipants/{pacticipant}/branches/{branch}"
41
+ }
42
+ }
43
+ }.to_json
44
+ end
45
+
46
+ let(:delete_response_body) do
47
+ { "some" => "error message" }.to_json
48
+ end
49
+
50
+ subject { DeleteBranch.call(params, options, pact_broker_client_options) }
51
+
52
+ context "when the branch is deleted" do
53
+ it "returns a success result" do
54
+ expect(subject.success).to be true
55
+ expect(subject.message).to include "Successfully deleted branch main of pacticipant Foo"
56
+ end
57
+ end
58
+
59
+ context "when there is a non-404 error" do
60
+ let(:delete_response_status) { 403 }
61
+
62
+ it "returns an error result with the response body" do
63
+ expect(subject.success).to be false
64
+ expect(subject.message).to include "error message"
65
+ end
66
+ end
67
+
68
+ context "when the branch is not found" do
69
+ let(:delete_response_status) { 404 }
70
+
71
+ context "when error_when_not_found is true" do
72
+ it "returns an error" do
73
+ expect(subject.success).to be false
74
+ expect(subject.message).to include "Could not delete branch main of pacticipant Foo as it was not found"
75
+ end
76
+ end
77
+
78
+ context "when error_when_not_found is false" do
79
+ let(:error_when_not_found) { false }
80
+
81
+ it "return a success" do
82
+ expect(subject.success).to be true
83
+ expect(subject.message).to include "Branch main of pacticipant Foo not found"
84
+ end
85
+ end
86
+ end
87
+
88
+ context "when deleting branches is not supported" do
89
+ let(:index_response_body) do
90
+ {
91
+ _links: {}
92
+ }.to_json
93
+ end
94
+
95
+ it "returns an error" do
96
+ expect(subject.success).to be false
97
+ expect(subject.message).to include "not support"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end