pact_broker-client 1.6.0 → 1.7.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +17 -0
  4. data/README.md +2 -1
  5. data/bin/pact-broker +4 -0
  6. data/gemfiles/default.gemfile.lock +29 -24
  7. data/gemfiles/ruby_under_22.gemfile.lock +25 -22
  8. data/lib/pact_broker/client/base_client.rb +16 -1
  9. data/lib/pact_broker/client/can_i_deploy.rb +80 -0
  10. data/lib/pact_broker/client/cli/broker.rb +52 -0
  11. data/lib/pact_broker/client/cli/publish.rb +9 -7
  12. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +29 -0
  13. data/lib/pact_broker/client/matrix.rb +39 -0
  14. data/lib/pact_broker/client/matrix/formatter.rb +20 -0
  15. data/lib/pact_broker/client/matrix/json_formatter.rb +13 -0
  16. data/lib/pact_broker/client/matrix/text_formatter.rb +33 -0
  17. data/lib/pact_broker/client/pact_broker_client.rb +5 -5
  18. data/lib/pact_broker/client/retry.rb +15 -4
  19. data/lib/pact_broker/client/version.rb +1 -1
  20. data/pact-broker-client.gemspec +2 -2
  21. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +85 -0
  22. data/spec/lib/pact_broker/client/cli/broker_spec.rb +81 -0
  23. data/spec/lib/pact_broker/client/cli/publish_spec.rb +6 -4
  24. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +43 -0
  25. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +29 -0
  26. data/spec/lib/pact_broker/client/matrix_spec.rb +16 -0
  27. data/spec/pacts/pact_broker_client-pact_broker.json +83 -0
  28. data/spec/service_providers/pact_broker_client_matrix_spec.rb +119 -0
  29. data/spec/spec_helper.rb +0 -5
  30. data/spec/support/matrix.json +23 -0
  31. data/spec/support/matrix.txt +3 -0
  32. data/spec/support/matrix_error.txt +3 -0
  33. metadata +50 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2da168156e0a87c5ada9a57862ff68b35457aee7
4
- data.tar.gz: 6e7a10febc1466ffd8362d287be80c24a9cf99dd
3
+ metadata.gz: a8305e2cc46298df3b6b08f4209aacef58f9fd1b
4
+ data.tar.gz: 61f58e6adb4dcf2911aa031d4ecd58a48042c7a4
5
5
  SHA512:
6
- metadata.gz: 3366140d2ba0adc2a2a3a9d5d91d4821877a3a32b2b97348140d86a591b2eb0bb7333480d1c385d179d1a89dca2fd434ee5315daf5723d49bea50cb4578a3830
7
- data.tar.gz: df9d0e2fad9fc73a7d890ab7c283700e8c169d8f8ebb094de21bf54fa7c5b7d8a3482ec62f34393c6bd47e8fa711815bde6302971dab5d0227965ecc030e3f00
6
+ metadata.gz: ff29557b0f7134e880bd7748ed4ac2e5b6c1fdfdc3f58ea1a8423213a914ddb4a1509b0c49943c8570c28db4bc9520c1e91fe88354341f52619f1cf4ab40ff96
7
+ data.tar.gz: 98656507dcf1571631e1c377fa28b0d2bc8780412a707615ade09c56f30918bbf682a2b8a8ab5ba943d7ae7ead971c25b790450c25a7fead68e010c12b4ca9ec
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
3
  - 2.1.8
5
4
  - 2.2.4
6
5
  - 2.3.1
6
+ - 2.4.1
7
7
  gemfile:
8
8
  - gemfiles/default.gemfile
9
9
  - gemfiles/ruby_under_22.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ <a name="v1.7.0"></a>
2
+ ### v1.7.0 (2017-10-19)
3
+
4
+
5
+ #### Features
6
+
7
+ * **can-i-deploy**
8
+ * change cli to use --name and --version options instead of bespoke version selector format ([15e8131](/../../commit/15e8131))
9
+ * puts output to stdout for both success and failure scenarios so that JSON output can be parsed by capturing stdout ([6db595a](/../../commit/6db595a))
10
+ * remove dates from table output and add success status ([5dc9484](/../../commit/5dc9484))
11
+ * add --output option allowing table or json to be specified ([57fa24e](/../../commit/57fa24e))
12
+
13
+ * changed name of verification date field ([962b7d1](/../../commit/962b7d1))
14
+ * output table of verification results when present ([9220703](/../../commit/9220703))
15
+ * add 'pact-broker can-i-deploy' executable ([ca68c54](/../../commit/ca68c54))
16
+
17
+
1
18
  <a name="v1.6.0"></a>
2
19
  ### v1.6.0 (2017-10-01)
3
20
 
data/README.md CHANGED
@@ -24,9 +24,10 @@ require 'pact_broker/client/tasks'
24
24
  PactBroker::Client::PublicationTask.new do | task |
25
25
  require 'my_consumer/version'
26
26
  task.consumer_version = MyConsumer::VERSION
27
+ task.pattern = 'custom/path/to/pacts/*.json' # optional, default value is 'spec/pacts/*.json'
27
28
  task.pact_broker_base_url = "http://pact-broker.my.org"
28
29
  task.tags = ["dev"] # optional
29
- task.pact_broker_basic_auth = { username: 'basic_auth_user', password: 'basic_auth_pass'} #optional
30
+ task.pact_broker_basic_auth = { username: 'basic_auth_user', password: 'basic_auth_pass'} # optional
30
31
  task.write_method = :merge # optional, this will merge the published pact into an existing pact rather than overwriting it if one exists. Not recommended, as it makes a mulch of the workflow on the broker.
31
32
  end
32
33
  ```
data/bin/pact-broker ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pact_broker/client/cli/broker'
3
+
4
+ PactBroker::Client::CLI::Broker.start
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- pact_broker-client (1.6.0)
4
+ pact_broker-client (1.7.0)
5
5
  httparty
6
6
  json
7
+ table_print (~> 1.5)
7
8
  term-ansicolor
8
9
 
9
10
  GEM
@@ -16,20 +17,22 @@ GEM
16
17
  rake
17
18
  thor (>= 0.14.0)
18
19
  awesome_print (1.8.0)
20
+ byebug (9.1.0)
19
21
  coderay (1.1.2)
20
22
  conventional-changelog (1.3.0)
21
23
  crack (0.4.3)
22
24
  safe_yaml (~> 1.0.0)
23
25
  diff-lcs (1.3)
24
- fakefs (0.11.2)
26
+ fakefs (0.11.3)
27
+ filelock (1.1.1)
25
28
  find_a_port (1.0.1)
26
- hashdiff (0.3.6)
29
+ hashdiff (0.3.7)
27
30
  httparty (0.15.6)
28
31
  multi_xml (>= 0.5.2)
29
32
  json (2.1.0)
30
33
  method_source (0.9.0)
31
34
  multi_xml (0.6.0)
32
- pact (1.16.0)
35
+ pact (1.16.1)
33
36
  json (> 1.8.5)
34
37
  pact-mock_service (~> 2.0)
35
38
  pact-support (~> 1.1, >= 1.1.8)
@@ -39,17 +42,18 @@ GEM
39
42
  term-ansicolor (~> 1.0)
40
43
  thor
41
44
  webrick
42
- pact-mock_service (2.2.0)
45
+ pact-mock_service (2.4.0)
46
+ filelock (~> 1.1)
43
47
  find_a_port (~> 1.0.1)
44
48
  json
45
- pact-support (~> 1.2)
49
+ pact-support (~> 1.2, >= 1.2.1)
46
50
  rack (~> 2.0)
47
51
  rack-test (~> 0.6.2)
48
52
  rspec (>= 2.14)
49
53
  term-ansicolor (~> 1.0)
50
54
  thor (~> 0.19)
51
55
  webrick (~> 1.3)
52
- pact-support (1.2.0)
56
+ pact-support (1.2.1)
53
57
  awesome_print (~> 1.1)
54
58
  find_a_port (~> 1.0.1)
55
59
  json
@@ -58,36 +62,38 @@ GEM
58
62
  rspec (>= 2.14)
59
63
  term-ansicolor (~> 1.0)
60
64
  thor
61
- pry (0.11.1)
65
+ pry (0.11.2)
62
66
  coderay (~> 1.1.0)
63
67
  method_source (~> 0.9.0)
68
+ pry-byebug (3.5.0)
69
+ byebug (~> 9.1)
70
+ pry (~> 0.10)
64
71
  public_suffix (3.0.0)
65
72
  rack (2.0.3)
66
73
  rack-test (0.6.3)
67
74
  rack (>= 1.0)
68
75
  rake (10.0.4)
69
76
  randexp (0.1.7)
70
- rspec (3.6.0)
71
- rspec-core (~> 3.6.0)
72
- rspec-expectations (~> 3.6.0)
73
- rspec-mocks (~> 3.6.0)
74
- rspec-core (3.6.0)
75
- rspec-support (~> 3.6.0)
76
- rspec-expectations (3.6.0)
77
+ rspec (3.7.0)
78
+ rspec-core (~> 3.7.0)
79
+ rspec-expectations (~> 3.7.0)
80
+ rspec-mocks (~> 3.7.0)
81
+ rspec-core (3.7.0)
82
+ rspec-support (~> 3.7.0)
83
+ rspec-expectations (3.7.0)
77
84
  diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.6.0)
79
- rspec-fire (1.3.0)
80
- rspec (>= 2.11, < 4)
81
- rspec-mocks (3.6.0)
85
+ rspec-support (~> 3.7.0)
86
+ rspec-mocks (3.7.0)
82
87
  diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.6.0)
84
- rspec-support (3.6.0)
88
+ rspec-support (~> 3.7.0)
89
+ rspec-support (3.7.0)
85
90
  safe_yaml (1.0.4)
91
+ table_print (1.5.6)
86
92
  term-ansicolor (1.6.0)
87
93
  tins (~> 1.0)
88
94
  thor (0.20.0)
89
95
  tins (1.15.0)
90
- webmock (3.0.1)
96
+ webmock (3.1.0)
91
97
  addressable (>= 2.3.6)
92
98
  crack (>= 0.3.2)
93
99
  hashdiff
@@ -102,9 +108,8 @@ DEPENDENCIES
102
108
  fakefs (~> 0.4)
103
109
  pact (~> 1.16)
104
110
  pact_broker-client!
105
- pry
111
+ pry-byebug
106
112
  rake (~> 10.0.3)
107
- rspec-fire
108
113
  webmock (~> 3.0)
109
114
 
110
115
  BUNDLED WITH
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- pact_broker-client (1.6.0)
4
+ pact_broker-client (1.7.0)
5
5
  httparty
6
6
  json
7
+ table_print (~> 1.5)
7
8
  term-ansicolor
8
9
 
9
10
  GEM
@@ -16,20 +17,21 @@ GEM
16
17
  rake
17
18
  thor (>= 0.14.0)
18
19
  awesome_print (1.8.0)
20
+ byebug (9.1.0)
19
21
  coderay (1.1.2)
20
22
  conventional-changelog (1.3.0)
21
23
  crack (0.4.3)
22
24
  safe_yaml (~> 1.0.0)
23
25
  diff-lcs (1.3)
24
- fakefs (0.11.2)
26
+ fakefs (0.11.3)
25
27
  find_a_port (1.0.1)
26
- hashdiff (0.3.6)
28
+ hashdiff (0.3.7)
27
29
  httparty (0.15.6)
28
30
  multi_xml (>= 0.5.2)
29
31
  json (2.1.0)
30
32
  method_source (0.9.0)
31
33
  multi_xml (0.6.0)
32
- pact (1.16.0)
34
+ pact (1.16.1)
33
35
  json (> 1.8.5)
34
36
  pact-mock_service (~> 2.0)
35
37
  pact-support (~> 1.1, >= 1.1.8)
@@ -49,7 +51,7 @@ GEM
49
51
  term-ansicolor (~> 1.0)
50
52
  thor
51
53
  webrick
52
- pact-support (1.2.0)
54
+ pact-support (1.2.1)
53
55
  awesome_print (~> 1.1)
54
56
  find_a_port (~> 1.0.1)
55
57
  json
@@ -58,36 +60,38 @@ GEM
58
60
  rspec (>= 2.14)
59
61
  term-ansicolor (~> 1.0)
60
62
  thor
61
- pry (0.11.1)
63
+ pry (0.11.2)
62
64
  coderay (~> 1.1.0)
63
65
  method_source (~> 0.9.0)
66
+ pry-byebug (3.5.0)
67
+ byebug (~> 9.1)
68
+ pry (~> 0.10)
64
69
  public_suffix (3.0.0)
65
70
  rack (1.6.8)
66
71
  rack-test (0.6.3)
67
72
  rack (>= 1.0)
68
73
  rake (10.0.4)
69
74
  randexp (0.1.7)
70
- rspec (3.6.0)
71
- rspec-core (~> 3.6.0)
72
- rspec-expectations (~> 3.6.0)
73
- rspec-mocks (~> 3.6.0)
74
- rspec-core (3.6.0)
75
- rspec-support (~> 3.6.0)
76
- rspec-expectations (3.6.0)
75
+ rspec (3.7.0)
76
+ rspec-core (~> 3.7.0)
77
+ rspec-expectations (~> 3.7.0)
78
+ rspec-mocks (~> 3.7.0)
79
+ rspec-core (3.7.0)
80
+ rspec-support (~> 3.7.0)
81
+ rspec-expectations (3.7.0)
77
82
  diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.6.0)
79
- rspec-fire (1.3.0)
80
- rspec (>= 2.11, < 4)
81
- rspec-mocks (3.6.0)
83
+ rspec-support (~> 3.7.0)
84
+ rspec-mocks (3.7.0)
82
85
  diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.6.0)
84
- rspec-support (3.6.0)
86
+ rspec-support (~> 3.7.0)
87
+ rspec-support (3.7.0)
85
88
  safe_yaml (1.0.4)
89
+ table_print (1.5.6)
86
90
  term-ansicolor (1.6.0)
87
91
  tins (~> 1.0)
88
92
  thor (0.20.0)
89
93
  tins (1.15.0)
90
- webmock (3.0.1)
94
+ webmock (3.1.0)
91
95
  addressable (>= 2.3.6)
92
96
  crack (>= 0.3.2)
93
97
  hashdiff
@@ -102,10 +106,9 @@ DEPENDENCIES
102
106
  fakefs (~> 0.4)
103
107
  pact (~> 1.16)
104
108
  pact_broker-client!
105
- pry
109
+ pry-byebug
106
110
  rack (< 2.0)
107
111
  rake (~> 10.0.3)
108
- rspec-fire
109
112
  webmock (~> 3.0)
110
113
 
111
114
  BUNDLED WITH
@@ -1,9 +1,12 @@
1
1
  require 'erb'
2
2
  require 'httparty'
3
+ require 'pact_broker/client/error'
3
4
 
4
5
  module PactBroker
5
6
  module Client
6
7
 
8
+ class Error < StandardError; end
9
+
7
10
  module UrlHelpers
8
11
  def encode_param param
9
12
  ERB::Util.url_encode param
@@ -31,6 +34,7 @@ module PactBroker
31
34
  def initialize options
32
35
  @base_url = options[:base_url]
33
36
  @client_options = options[:client_options] || {}
37
+ @verbose = @client_options[:verbose]
34
38
  self.class.base_uri base_url
35
39
  self.class.basic_auth(client_options[:basic_auth][:username], client_options[:basic_auth][:password]) if client_options[:basic_auth]
36
40
  end
@@ -56,8 +60,16 @@ module PactBroker
56
60
  yield
57
61
  elsif response.code == 404
58
62
  nil
63
+ elsif response.code == 401
64
+ raise Error.new("Authentication failed")
59
65
  else
60
- raise response.body
66
+ error_message = nil
67
+ begin
68
+ error_message = JSON.parse(response.body)['errors'].join("\n")
69
+ rescue
70
+ raise Error.new(response.body)
71
+ end
72
+ raise Error.new(error_message)
61
73
  end
62
74
  end
63
75
 
@@ -73,6 +85,9 @@ module PactBroker
73
85
  self.class.get(url, *args)
74
86
  end
75
87
 
88
+ def verbose?
89
+ @verbose
90
+ end
76
91
  end
77
92
  end
78
93
  end
@@ -0,0 +1,80 @@
1
+ require 'pact_broker/client/error'
2
+ require 'pact_broker/client/pact_broker_client'
3
+ require 'pact_broker/client/retry'
4
+ require 'pact_broker/client/matrix/formatter'
5
+
6
+
7
+ module PactBroker
8
+ module Client
9
+ class CanIDeploy
10
+
11
+ class Result
12
+ attr_reader :success, :message
13
+
14
+ def initialize success, message = nil
15
+ @success = success
16
+ @message = message
17
+ end
18
+ end
19
+
20
+ def self.call(pact_broker_base_url, version_selectors, options, pact_broker_client_options={})
21
+ new(pact_broker_base_url, version_selectors, options, pact_broker_client_options).call
22
+ end
23
+
24
+ def initialize(pact_broker_base_url, version_selectors, options, pact_broker_client_options)
25
+ @pact_broker_base_url = pact_broker_base_url
26
+ @version_selectors = version_selectors
27
+ @options = options
28
+ @pact_broker_client_options = pact_broker_client_options
29
+ end
30
+
31
+ def call
32
+ if matrix[:summary][:compatible]
33
+ Result.new(true, success_message(matrix))
34
+ else
35
+ Result.new(false, failure_message(matrix))
36
+ end
37
+ rescue PactBroker::Client::Error => e
38
+ Result.new(false, e.message)
39
+ rescue StandardError => e
40
+ Result.new(false, "Error retrieving matrix. #{e.class} - #{e.message}\n#{e.backtrace.join("\n")}")
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :pact_broker_base_url, :version_selectors, :options, :pact_broker_client_options
46
+
47
+ def success_message(matrix)
48
+ message = format_matrix(matrix[:matrix])
49
+ if format != 'json'
50
+ message = 'Computer says yes \o/' + "\n\n" + message
51
+ end
52
+ message
53
+ end
54
+
55
+ def failure_message(matrix)
56
+ message = format_matrix(matrix[:matrix])
57
+ if format != 'json'
58
+ message = 'Computer says no ¯\_(ツ)_/¯' + "\n\n" + message
59
+ end
60
+ message
61
+ end
62
+
63
+ def format_matrix(matrix)
64
+ Matrix::Formatter.call(matrix, format)
65
+ end
66
+
67
+ def format
68
+ options[:output]
69
+ end
70
+
71
+ def matrix
72
+ @matrix ||= Retry.until_true { pact_broker_client.matrix.get(version_selectors) }
73
+ end
74
+
75
+ def pact_broker_client
76
+ @pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,52 @@
1
+ require 'pact_broker/client/can_i_deploy'
2
+ require 'pact_broker/client/version'
3
+ require 'pact_broker/client/cli/version_selector_options_parser'
4
+ require 'thor'
5
+
6
+ module PactBroker
7
+ module Client
8
+ module CLI
9
+ class Broker < Thor
10
+ desc 'can-i-deploy', "Returns exit code 0 or 1, indicating whether or not the specified application versions are compatible."
11
+
12
+ method_option :name, required: true, aliases: "-n", desc: "The application name. Use once for each pacticipant being checked."
13
+ method_option :version, required: true, aliases: "-a", desc: "The application version. Must be entered after a --name."
14
+ method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
15
+ method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
16
+ method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
17
+ method_option :output, aliases: "-o", desc: "json or table", default: 'table'
18
+ method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false
19
+
20
+ def can_i_deploy
21
+ selectors = VersionSelectorOptionsParser.call(ARGV)
22
+ result = CanIDeploy.call(options.broker_base_url, selectors, {output: options.output}, pact_broker_client_options)
23
+ $stdout.puts result.message
24
+ exit(1) unless result.success
25
+ end
26
+
27
+ desc 'version', "Show the pact_broker-client gem version"
28
+ def version
29
+ $stdout.puts PactBroker::Client::VERSION
30
+ end
31
+
32
+ no_commands do
33
+ def pact_broker_client_options
34
+ if options.broker_username
35
+ {
36
+ basic_auth: {
37
+ username: options.broker_username,
38
+ password: options.broker_password
39
+ },
40
+ verbose: options.verbose
41
+ }
42
+ else
43
+ {
44
+ verbose: options.verbose
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end