pact_broker-client 1.20.0 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36bf162b7373bf5c66a1144647bc90cec11eceea
4
- data.tar.gz: ac2f6395bd8882eb2711af95bb999c9dda3678cb
3
+ metadata.gz: e1bafd46273980e0df06f1e067e9f129aa2097c4
4
+ data.tar.gz: 62076387c8985fb1ec56b95833f5f118e333625f
5
5
  SHA512:
6
- metadata.gz: d6f31eadfca03d30063b7377d83792f45f44e0ef71f700ae34cafbe9d0d950d21e2cf19ebd57203329a7e5306ab57fb3b22ace88e42c2142b2ed3aba1ecdecbb
7
- data.tar.gz: e0fd38b680973acdca44a52935f3c2317c4e23894c8642c63fdf08ebad6e848e4120d2e6a10f7a68fee291c3c17f7808a4c40ebe07dec896ba461df01bfd5c4c
6
+ metadata.gz: d45c1c54457176cd83bf71212d96549899236de9cfc496de52bc17dd4d39247de7b8ae53dee0119c35ebeb7b9145bfc2d325de94bed4741d9b362d06a44562ba
7
+ data.tar.gz: 39587a85fa5e267de6288067fcd31d981cf71edd50084430cc82d4170b3cc5447137a8084e06bb9113cc25aba08e404aae5417cdbc3c61f7650ac27e0afff34a
@@ -2,4 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.4
4
4
  - 2.3.1
5
- - 2.4.1
5
+ - 2.4.1
@@ -1,3 +1,21 @@
1
+ <a name="v1.21.0"></a>
2
+ ### v1.21.0 (2020-01-16)
3
+
4
+
5
+ #### Features
6
+
7
+ * attempt to get git branch name from environment variable first before running git ([122973b](/../../commit/122973b))
8
+
9
+
10
+ #### Bug Fixes
11
+
12
+ * **can-i-deploy**
13
+ * if only one selector is specified and no --to TAG is specified, set latest=true for automatically calculated dependencies ([ec10b72](/../../commit/ec10b72))
14
+
15
+ * remove -u alias for --broker-username for create-webhook as it clashes with the -u from the curl command ([9463eff](/../../commit/9463eff))
16
+ * Fix invalid environment variable names in can-i-deploy docs ([2b26081](/../../commit/2b26081))
17
+
18
+
1
19
  <a name="v1.20.0"></a>
2
20
  ### v1.20.0 (2019-08-27)
3
21
 
data/README.md CHANGED
@@ -59,7 +59,7 @@ Add a tag to a pacticipant version
59
59
 
60
60
  ### can-i-deploy
61
61
 
62
- You will need >= v2.13.0 of the Pact Broker for this feature to work.
62
+ You will need >= v2.13.0 of the Pact Broker for this feature to work. See the [Can I Deploy](https://docs.pact.io/pact_broker/can_i_deploy) page in the Pact docs for an explanation of how `can-i-deploy` works under the hood.
63
63
 
64
64
  ```
65
65
  Usage:
@@ -88,65 +88,92 @@ Description:
88
88
 
89
89
  The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_BASE_URL_USERNAME and PACT_BROKER_BASE_URL_PASSWORD may be used
90
90
  instead of their respective command line options.
91
+ ```
91
92
 
92
- SCENARIOS
93
+ Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) versions are compatible (ie. safe to deploy). Prints out the relevant pact/verification details, indicating any missing or failed verification results.
93
94
 
94
- # If every build goes straight to production
95
+ The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD may be used instead of their respective command line options.
95
96
 
96
- Check the status of the pacts for a pacticipant version. Note that this only checks that the most recent verification for each
97
- pact is successful. It doesn't provide any assurance that the pact has been verified by the *production* version of the
98
- provider, however, it is sufficient if you are doing true continuous deployment.
97
+ There are two ways to use `can-i-deploy`. The first (recommended and most common) approach is to specify just the application version you want to deploy and let the Pact Broker work out the dependencies for you. The second approach is to specify each application version explicitly. This would generally only be used if there were limitations that stopped you being able to use the first approach.
99
98
 
100
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --broker-base-url BROKER_BASE_URL
99
+ #### Specifying an application version
101
100
 
102
- # If every build does NOT go straight to production
101
+ To specify an application (pacticipant) version you need to provide:
103
102
 
104
- ## Recommended approach
103
+ * the name of the application using the `--pacticipant PACTICIPANT` parameter,
104
+ * directly followed by *one* of the following parameters:
105
+ * `--version VERSION` to specify a known application version (recommended)
106
+ * `--latest` to specify the latest version
107
+ * `--latest TAG` to specify the latest version that has a particular tag
105
108
 
106
- If all applications within the pact network are not being deployed continuously (ie. if there is a gap between pact
107
- verification and actual deployment) then the following strategy is recommended. Each application version should be tagged in
108
- the broker with the name of the stage (eg. test, staging, production) as it is deployed (see the pact-broker create-version-tag
109
- CLI). This enables you to use the following very simple command to check if the application version you are about to deploy is
110
- compatible with every other application version already deployed in that environment.
109
+ Using a specific version is the easiest way to ensure you get an accurate response that won't be affected by race conditions.
111
110
 
112
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to TAG --broker-base-url BROKER_BASE_URL
111
+ #### Recommended usage - allowing the Pact Broker to automatically determine the dependencies
113
112
 
114
- ## Other approaches
113
+ If you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know what application versions are in that environment. To do this, the relevant application version resource in the Broker will need to be "tagged" with the name of the environment during the deployment process:
115
114
 
116
- If you do not/cannot tag every application at deployment, you have two options. You can either use the very first form of this
117
- command which just checks that the *latest* verification is successful (not recommended as it's the production version that you
118
- really care about) or you will need to determine the production versions of each collaborating application from some other
119
- source (eg. git) and explicitly reference each one using one using the format `--pacticipant PACTICIPANT1 --version VERSION1
120
- --pacticipant PACTICIPANT2 --version VERSION2 ...`
115
+ $ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test
121
116
 
122
- # Other commands
117
+ This allows you to use the following simple command to find out if you are safe to deploy:
123
118
 
124
- Check the status of the pacts for the latest pacticipant version. This form is not recommended for use in your CI as it is
125
- possible that the version you are about to deploy is not the the version that the Broker considers the latest. It's best to
126
- specify the version explicitly.
119
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION \
120
+ --to ENVIRONMENT \
121
+ --broker-base-url BROKER_BASE_URL
127
122
 
128
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --latest --broker-base-url BROKER_BASE_URL
123
+ If the `--to` tag is omitted, then the query will return the compatiblity with the overall latest version of each of the other applications.
129
124
 
130
- Check the status of the pacts for the latest pacticipant version for a given tag:
125
+ Examples:
131
126
 
132
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --latest TAG --broker-base-url BROKER_BASE_URL
133
127
 
134
- Check the status of the pacts between two (or more) specific pacticipant versions:
128
+ Can I deploy version 173153ae0 of application Foo to the test environment?
135
129
 
136
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --version VERSION1 --pacticipant PACTICIPANT2 --version VERSION2
137
- --broker-base-url BROKER_BASE_URL
138
130
 
139
- Check the status of the pacts between the latest versions of two (or more) pacticipants:
131
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
132
+ --to test \
133
+ --broker-base-url https://my-pact-broker
140
134
 
141
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest --pacticipant PACTICIPANT2 --latest --broker-base-url
142
- BROKER_BASE_URL
143
135
 
144
- Check the status of the pacts between the latest versions of two (or more) pacticipants with a given tag:
136
+ Can I deploy the latest version of application Foo with the latest version of each of the applications it integrates to?
145
137
 
146
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest TAG1 --pacticipant PACTICIPANT2 --latest TAG2 --broker-base-url
147
- BROKER_BASE_URL
148
138
 
149
- ```
139
+ $ pact-broker can-i-deploy --pacticipant Foo --latest \
140
+ --broker-base-url https://my-pact-broker
141
+
142
+
143
+ Can I deploy the latest version of the application Foo that has the tag "test" to the "prod" environment?
144
+
145
+ $ pact-broker can-i-deploy --pacticipant Foo --latest test \
146
+ --to prod \
147
+ --broker-base-url https://my-pact-broker
148
+
149
+
150
+
151
+ #### Alternate usage - specifying all dependencies explicitly
152
+
153
+ If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify each of the application versions explictly. You can specify as many application versions as you like.
154
+
155
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT_1 [--version VERSION_1 | --latest [TAG]] \
156
+ --pacticipant PACTICIPANT_2 [--version VERSION_2 | --latest [TAG_2]] \
157
+ --to ENVIRONMENT \
158
+ --broker-base-url BROKER_BASE_URL
159
+
160
+ Examples:
161
+
162
+
163
+ Can I deploy version Foo version 173153ae0 and Bar version ac23df1e8 together?
164
+
165
+
166
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
167
+ --pacticipant Bar --version ac23df1e8 \
168
+ --broker-base-url BROKER_BASE_URL
169
+
170
+
171
+ Can I deploy the latest version of Foo with tag "master" and the latest version of Bar with tag "master" together?
172
+
173
+ $ pact-broker can-i-deploy --pacticipant Foo --latest master \
174
+ --pacticipant Bar --latest master \
175
+ --broker-base-url BROKER_BASE_URL
176
+
150
177
 
151
178
  ### create-webhook
152
179
 
@@ -434,7 +434,7 @@ Given **the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6 an
434
434
  {
435
435
  "method": "get",
436
436
  "path": "/matrix",
437
- "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp"
437
+ "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp&latest=true"
438
438
  }
439
439
  ```
440
440
  Pact Broker will respond with:
@@ -109,14 +109,14 @@ module PactBroker
109
109
  exit(1) unless result.success
110
110
  end
111
111
 
112
- method_option :request, aliases: "-X", desc: "HTTP method", required: true
112
+ method_option :request, banner: "METHOD", aliases: "-X", desc: "HTTP method", required: true
113
113
  method_option :header, aliases: "-H", type: :array, desc: "Header"
114
114
  method_option :data, aliases: "-d", desc: "Data"
115
115
  method_option :user, aliases: "-u", desc: "Basic auth username and password eg. username:password"
116
116
  method_option :consumer, desc: "Consumer name"
117
117
  method_option :provider, desc: "Provider name"
118
118
  method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
119
- method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
119
+ method_option :broker_username, desc: "Pact Broker basic auth username"
120
120
  method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
121
121
  method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
122
122
  method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
@@ -1,45 +1,84 @@
1
- Returns exit code 0 or 1, indicating whether or not the specified pacticipant versions are compatible. Prints out the relevant pact/verification details.
1
+ Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) versions are compatible (ie. safe to deploy). Prints out the relevant pact/verification details, indicating any missing or failed verification results.
2
2
 
3
- The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_BASE_URL_USERNAME and PACT_BROKER_BASE_URL_PASSWORD may be used instead of their respective command line options.
3
+ The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD may be used instead of their respective command line options.
4
4
 
5
- SCENARIOS
5
+ There are two ways to use `can-i-deploy`. The first (recommended and most common) approach is to specify just the application version you want to deploy and let the Pact Broker work out the dependencies for you. The second approach is to specify each application version explicitly. This would generally only be used if there were limitations that stopped you being able to use the first approach.
6
6
 
7
- # If every build goes straight to production
7
+ #### Specifying an application version
8
8
 
9
- Check the status of the pacts for a pacticipant version. Note that this only checks that the most recent verification for each pact is successful. It doesn't provide any assurance that the pact has been verified by the *production* version of the provider, however, it is sufficient if you are doing true continuous deployment.
9
+ To specify an application (pacticipant) version you need to provide:
10
10
 
11
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --broker-base-url BROKER_BASE_URL
11
+ * the name of the application using the `--pacticipant PACTICIPANT` parameter,
12
+ * directly followed by *one* of the following parameters:
13
+ * `--version VERSION` to specify a known application version (recommended)
14
+ * `--latest` to specify the latest version
15
+ * `--latest TAG` to specify the latest version that has a particular tag
12
16
 
13
- # If every build does NOT go straight to production
17
+ Using a specific version is the easiest way to ensure you get an accurate response that won't be affected by race conditions.
14
18
 
15
- ## Recommended approach
19
+ #### Recommended usage - allowing the Pact Broker to automatically determine the dependencies
16
20
 
17
- If all applications within the pact network are not being deployed continuously (ie. if there is a gap between pact verification and actual deployment) then the following strategy is recommended. Each application version should be tagged in the broker with the name of the stage (eg. test, staging, production) as it is deployed (see the pact-broker create-version-tag CLI). This enables you to use the following very simple command to check if the application version you are about to deploy is compatible with every other application version already deployed in that environment.
21
+ If you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know what application versions are in that environment. To do this, the relevant application version resource in the Broker will need to be "tagged" with the name of the environment during the deployment process:
18
22
 
19
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to TAG --broker-base-url BROKER_BASE_URL
23
+ $ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test
20
24
 
21
- ## Other approaches
25
+ This allows you to use the following simple command to find out if you are safe to deploy:
22
26
 
23
- If you do not/cannot tag every application at deployment, you have two options. You can either use the very first form of this command which just checks that the *latest* verification is successful (not recommended as it's the production version that you really care about) or you will need to determine the production versions of each collaborating application from some other source (eg. git) and explicitly reference each one using one using the format `--pacticipant PACTICIPANT1 --version VERSION1 --pacticipant PACTICIPANT2 --version VERSION2 ...`
27
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION \
28
+ --to ENVIRONMENT \
29
+ --broker-base-url BROKER_BASE_URL
24
30
 
25
- # Other commands
31
+ If the `--to` tag is omitted, then the query will return the compatiblity with the overall latest version of each of the other applications.
26
32
 
27
- Check the status of the pacts for the latest pacticipant version. This form is not recommended for use in your CI as it is possible that the version you are about to deploy is not the the version that the Broker considers the latest. It's best to specify the version explicitly.
33
+ Examples:
28
34
 
29
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --latest --broker-base-url BROKER_BASE_URL
30
35
 
31
- Check the status of the pacts for the latest pacticipant version for a given tag:
36
+ Can I deploy version 173153ae0 of application Foo to the test environment?
32
37
 
33
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT --latest TAG --broker-base-url BROKER_BASE_URL
34
38
 
35
- Check the status of the pacts between two (or more) specific pacticipant versions:
39
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
40
+ --to test \
41
+ --broker-base-url https://my-pact-broker
36
42
 
37
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --version VERSION1 --pacticipant PACTICIPANT2 --version VERSION2 --broker-base-url BROKER_BASE_URL
38
43
 
39
- Check the status of the pacts between the latest versions of two (or more) pacticipants:
44
+ Can I deploy the latest version of application Foo with the latest version of each of the applications it integrates to?
40
45
 
41
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest --pacticipant PACTICIPANT2 --latest --broker-base-url BROKER_BASE_URL
42
46
 
43
- Check the status of the pacts between the latest versions of two (or more) pacticipants with a given tag:
47
+ $ pact-broker can-i-deploy --pacticipant Foo --latest \
48
+ --broker-base-url https://my-pact-broker
49
+
50
+
51
+ Can I deploy the latest version of the application Foo that has the tag "test" to the "prod" environment?
52
+
53
+ $ pact-broker can-i-deploy --pacticipant Foo --latest test \
54
+ --to prod \
55
+ --broker-base-url https://my-pact-broker
56
+
57
+
58
+
59
+ #### Alternate usage - specifying all dependencies explicitly
60
+
61
+ If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify each of the application versions explictly. You can specify as many application versions as you like.
62
+
63
+ $ pact-broker can-i-deploy --pacticipant PACTICIPANT_1 [--version VERSION_1 | --latest [TAG]] \
64
+ --pacticipant PACTICIPANT_2 [--version VERSION_2 | --latest [TAG_2]] \
65
+ --to ENVIRONMENT \
66
+ --broker-base-url BROKER_BASE_URL
67
+
68
+ Examples:
69
+
70
+
71
+ Can I deploy version Foo version 173153ae0 and Bar version ac23df1e8 together?
72
+
73
+
74
+ $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
75
+ --pacticipant Bar --version ac23df1e8 \
76
+ --broker-base-url BROKER_BASE_URL
77
+
78
+
79
+ Can I deploy the latest version of Foo with tag "master" and the latest version of Bar with tag "master" together?
80
+
81
+ $ pact-broker can-i-deploy --pacticipant Foo --latest master \
82
+ --pacticipant Bar --latest master \
83
+ --broker-base-url BROKER_BASE_URL
44
84
 
45
- $ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest TAG1 --pacticipant PACTICIPANT2 --latest TAG2 --broker-base-url BROKER_BASE_URL
@@ -1,22 +1,69 @@
1
1
  require 'pact_broker/client/error'
2
2
 
3
- # BUILDKITE_BRANCH BUILDKITE_COMMIT https://buildkite.com/docs/pipelines/environment-variables
4
- # CIRCLE_BRANCH CIRCLE_SHA1 https://circleci.com/docs/2.0/env-vars/
5
- # TRAVIS_COMMIT TRAVIS_BRANCH - TRAVIS_PULL_REQUEST_BRANCH TRAVIS_PULL_REQUEST_SHA https://docs.travis-ci.com/user/environment-variables/
6
- # GIT_COMMIT GIT_BRANCH https://wiki.jenkins.io/display/JENKINS/Building+a+software+project
7
- # GIT_COMMIT GIT_LOCAL_BRANCH https://hudson.eclipse.org/webtools/env-vars.html/
8
- # APPVEYOR_REPO_COMMIT APPVEYOR_REPO_BRANCH https://www.appveyor.com/docs/environment-variables/
9
- # bamboo.repository.git.branch https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html
3
+ =begin
10
4
 
5
+ BUILDKITE_BRANCH BUILDKITE_COMMIT https://buildkite.com/docs/pipelines/environment-variables
6
+ CIRCLE_BRANCH CIRCLE_SHA1 https://circleci.com/docs/2.0/env-vars/
7
+ TRAVIS_COMMIT TRAVIS_BRANCH - TRAVIS_PULL_REQUEST_BRANCH TRAVIS_PULL_REQUEST_SHA https://docs.travis-ci.com/user/environment-variables/
8
+ GIT_COMMIT GIT_BRANCH https://wiki.jenkins.io/display/JENKINS/Building+a+software+project
9
+ GIT_COMMIT GIT_LOCAL_BRANCH https://hudson.eclipse.org/webtools/env-vars.html/
10
+ APPVEYOR_REPO_COMMIT APPVEYOR_REPO_BRANCH https://www.appveyor.com/docs/environment-variables/
11
+ CI_COMMIT_REF_NAME https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
12
+ CI_BRANCH CI_COMMIT_ID https://documentation.codeship.com/pro/builds-and-configuration/environment-variables/
13
+ bamboo.repository.git.branch https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html
14
+
15
+ =end
16
+
17
+ # Keep in sync with pact-provider-verifier/lib/pact/provider_verifier/git.rb
11
18
  module PactBroker
12
19
  module Client
13
20
  module Git
14
- COMMAND = 'git rev-parse --abbrev-ref HEAD'
21
+ COMMAND = 'git name-rev --name-only HEAD'.freeze
22
+ BRANCH_ENV_VAR_NAMES = %w{BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME}.freeze
15
23
 
16
24
  def self.branch
17
- `#{COMMAND}`.strip
18
- rescue StandardError => e
19
- raise PactBroker::Client::Error, "Could not determine current git branch using command `#{COMMAND}`. #{e.class} #{e.message}"
25
+ find_branch_from_env_vars || branch_from_git_command
26
+ end
27
+
28
+ # private
29
+
30
+ def self.find_branch_from_env_vars
31
+ BRANCH_ENV_VAR_NAMES.collect { |env_var_name| branch_from_env_var(env_var_name) }.compact.first
32
+ end
33
+
34
+ def self.branch_from_env_var(env_var_name)
35
+ val = ENV[env_var_name]
36
+ if val && val.strip.size > 0
37
+ val
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ def self.branch_from_git_command
44
+ branch_name = nil
45
+ begin
46
+ branch_name = execute_git_command.strip
47
+ rescue StandardError => e
48
+ raise PactBroker::Client::Error, "Could not determine current git branch using command `#{COMMAND}`. #{e.class} #{e.message}"
49
+ end
50
+
51
+ validate_branch_name(branch_name)
52
+ branch_name
53
+ end
54
+
55
+ def self.validate_branch_name(branch_name)
56
+ if !branch_name || branch_name.size == 0
57
+ raise PactBroker::Client::Error, "Command `#{COMMAND}` returned an empty string when trying to determine the git branch name. This is most likely not the value you want. You will need to get the branch name another way."
58
+ end
59
+
60
+ if branch_name == "HEAD"
61
+ raise PactBroker::Client::Error, "Command `#{COMMAND}` returned 'HEAD' when trying to determine the git branch name. This is probably because the repository is in detatched HEAD state. HEAD is most likely not the value you want. You will need to get the branch name another way."
62
+ end
63
+ end
64
+
65
+ def self.execute_git_command
66
+ `#{COMMAND}`
20
67
  end
21
68
  end
22
69
  end
@@ -41,6 +41,10 @@ module PactBroker
41
41
  wrap_response(href, @http_client.get(href, payload, headers))
42
42
  end
43
43
 
44
+ def get!(*args)
45
+ get(*args).assert_success!
46
+ end
47
+
44
48
  def put(payload = nil, headers = {})
45
49
  wrap_response(href, @http_client.put(href, payload ? JSON.dump(payload) : nil, headers))
46
50
  end
@@ -9,7 +9,7 @@ module PactBroker
9
9
  query = {
10
10
  q: convert_selector_hashes_to_params(selectors),
11
11
  latestby: latestby
12
- }.merge(query_options(options))
12
+ }.merge(query_options(options, selectors))
13
13
  response = self.class.get("/matrix", query: query, headers: default_get_headers)
14
14
  response = handle_response(response) do
15
15
  Matrix::Resource.new(JSON.parse(response.body, symbolize_names: true))
@@ -41,7 +41,7 @@ module PactBroker
41
41
  end
42
42
  end
43
43
 
44
- def query_options(options)
44
+ def query_options(options, selectors)
45
45
  opts = {}
46
46
  if options.key?(:success)
47
47
  opts[:success] = [*options[:success]]
@@ -50,6 +50,8 @@ module PactBroker
50
50
  if options[:to_tag]
51
51
  opts[:latest] = 'true'
52
52
  opts[:tag] = options[:to_tag]
53
+ elsif selectors.size == 1
54
+ opts[:latest] = 'true'
53
55
  end
54
56
  opts
55
57
  end
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.20.0'
3
+ VERSION = '1.21.0'
4
4
  end
5
5
  end
@@ -41,7 +41,7 @@ module PactBroker
41
41
  end
42
42
 
43
43
  def create_webhook_with_optional_consumer_and_provider
44
- webhook_entity = index_link.get._link("pb:webhooks").post(request_body_with_optional_consumer_and_provider)
44
+ webhook_entity = index_link.get!._link("pb:webhooks").post(request_body_with_optional_consumer_and_provider)
45
45
 
46
46
  if webhook_entity.response.status == 405
47
47
  raise PactBroker::Client::Error.new(WEBHOOKS_WITH_OPTIONAL_PACTICICPANTS_NOT_SUPPORTED)
@@ -0,0 +1,65 @@
1
+ require 'pact_broker/client/git'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Git
6
+ describe ".branch" do
7
+ before do
8
+ allow(ENV).to receive(:[]).and_call_original
9
+ Git::BRANCH_ENV_VAR_NAMES.each do | env_var_name |
10
+ allow(ENV).to receive(:[]).with(env_var_name).and_return(nil)
11
+ end
12
+ end
13
+
14
+ subject { Git.branch }
15
+
16
+ context "when there is a known environment variable for the branch" do
17
+ before do
18
+ allow(ENV).to receive(:[]).with("BUILDKITE_BRANCH").and_return("")
19
+ allow(ENV).to receive(:[]).with("TRAVIS_BRANCH").and_return("foo")
20
+ end
21
+
22
+ it "returns the value of the environment variable" do
23
+ expect(subject).to eq "foo"
24
+ end
25
+ end
26
+
27
+ context "when there is no known environment variable for the branch" do
28
+ it "attempts to execute a git command to determine the value" do
29
+ expect { subject }.to_not raise_error
30
+ end
31
+ end
32
+
33
+ context "when the git branch name comes back as HEAD" do
34
+ before do
35
+ allow(Git).to receive(:execute_git_command).and_return("HEAD")
36
+ end
37
+
38
+ it "raises an error" do
39
+ expect { subject }.to raise_error PactBroker::Client::Error, /returned 'HEAD'/
40
+ end
41
+ end
42
+
43
+ context "when the git branch name comes back as an empty string" do
44
+ before do
45
+ allow(Git).to receive(:execute_git_command).and_return("")
46
+ end
47
+
48
+ it "raises an error" do
49
+ expect { subject }.to raise_error PactBroker::Client::Error, /an empty string/
50
+ end
51
+ end
52
+
53
+ context "when there is an error executing the git command" do
54
+ before do
55
+ allow(Git).to receive(:execute_git_command).and_raise("some error")
56
+ end
57
+
58
+ it "raises an error" do
59
+ expect { subject }.to raise_error PactBroker::Client::Error, /some error/
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -292,7 +292,7 @@
292
292
  "request": {
293
293
  "method": "get",
294
294
  "path": "/matrix",
295
- "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp"
295
+ "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp&latest=true"
296
296
  },
297
297
  "response": {
298
298
  "status": 200,
@@ -67,7 +67,7 @@ module PactBroker::Client
67
67
  with(
68
68
  method: :get,
69
69
  path: "/matrix",
70
- query: "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp"
70
+ query: "q[][pacticipant]=Foo&q[][version]=1.2.3&latestby=cvp&latest=true"
71
71
  ).
72
72
  will_respond_with(
73
73
  status: 200,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.0
4
+ version: 1.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-26 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -248,6 +248,7 @@ files:
248
248
  - spec/lib/pact_broker/client/cli/broker_publish_spec.rb
249
249
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
250
250
  - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
251
+ - spec/lib/pact_broker/client/git_spec.rb
251
252
  - spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb
252
253
  - spec/lib/pact_broker/client/hal/entity_spec.rb
253
254
  - spec/lib/pact_broker/client/hal/http_client_spec.rb
@@ -308,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
309
  version: '0'
309
310
  requirements: []
310
311
  rubyforge_project:
311
- rubygems_version: 2.6.11
312
+ rubygems_version: 2.6.14.3
312
313
  signing_key:
313
314
  specification_version: 4
314
315
  summary: See description
@@ -322,6 +323,7 @@ test_files:
322
323
  - spec/lib/pact_broker/client/cli/broker_publish_spec.rb
323
324
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
324
325
  - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
326
+ - spec/lib/pact_broker/client/git_spec.rb
325
327
  - spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb
326
328
  - spec/lib/pact_broker/client/hal/entity_spec.rb
327
329
  - spec/lib/pact_broker/client/hal/http_client_spec.rb