Skip to content

Commit

Permalink
chore: simplify? auto detect consumer_version logic
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jul 28, 2023
1 parent 0cda22f commit 630ab6a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ Options:
-h, [--branch=BRANCH]
# Repository branch of the consumer version
-r, [--auto-detect-version-properties], [--no-auto-detect-version-properties]
# 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.
# Automatically detect the repository commit and 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.
-t, [--tag=TAG]
# Tag name for consumer version. Can be specified multiple
times.
Expand Down Expand Up @@ -497,8 +497,8 @@ Description:
support for environments, deployments and releases. For documentation on how to use can-i-deploy with tags, please see
https://docs.pact.io/pact_broker/client_cli/can_i_deploy_usage_with_tags/

Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The "test"
and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The
"test" and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
https://docs.pact.io/pact_broker/client_cli/readme#environments for more information.

$ pact-broker create-environment --name "uat" --display-name "UAT" --no-production
Expand All @@ -508,17 +508,17 @@ Description:

$ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment uat

Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy with
the versions of each integrated application that are already in that environment.
Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy
with the versions of each integrated application that are already in that environment.

$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to-environment ENVIRONMENT

Example: can I deploy version 173153ae0 of application Foo to the test environment?

$ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 --to-environment test

Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the latest version
from the main branch of another application" it functions as a "can I merge" check.
Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the
latest version from the main branch of another application" it functions as a "can I merge" check.

$ pact-broker can-i-deploy --pacticipant Foo 173153ae0 \ --pacticipant Bar --latest main

Expand Down Expand Up @@ -671,8 +671,8 @@ Options:
```

Description:
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the consumer,
provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the
consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.

Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl
option. Please use the --broker-username or environment variable for the Pact Broker username.
Expand Down Expand Up @@ -736,9 +736,9 @@ Options:
```

Description:
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the
consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must
also be provided. You can generate a valid UUID by using the `generate-uuid` command.
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and
add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid
must also be provided. You can generate a valid UUID by using the `generate-uuid` command.

Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl
option. Please use the --broker-username or environment variable for the Pact Broker username.
Expand Down
2 changes: 1 addition & 1 deletion doc/pacts/markdown/Pact Broker Client - Pactflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Given **there is a pf:ui href in the response**, upon receiving **a request to c
}
}
```
Pactflow will respond with:
PactFlow will respond with:
```json
{
"status": 201,
Expand Down
2 changes: 1 addition & 1 deletion doc/pacts/markdown/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Pacts for Pact Broker Client

* [Pact Broker](Pact%20Broker%20Client%20-%20Pact%20Broker.md)
* [PactFlow](Pact%20Broker%20Client%20-%20Pactflow.md)
* [PactFlow](Pact%20Broker%20Client%20-%20PactFlow.md)
6 changes: 2 additions & 4 deletions lib/pact_broker/client/cli/pact_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module PactCommands
def self.included(thor)
thor.class_eval do
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
method_option :consumer_app_version, aliases: "-a", desc: "The consumer application version", default: ''
method_option :consumer_app_version, aliases: "-a", desc: "The consumer application version"
method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
method_option :auto_detect_version_properties, aliases: "-r", 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."
method_option :auto_detect_version_properties, aliases: "-r", type: :boolean, default: false, desc: "Automatically detect the repository commit and 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."
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
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"
method_option :build_url, desc: "The build URL that created the pact"
Expand Down Expand Up @@ -122,8 +122,6 @@ def consumer_app_version
require 'pact_broker/client/git'
if options.consumer_app_version.blank? && options.auto_detect_version_properties
PactBroker::Client::Git.commit(raise_error: explict_auto_detect_version_properties)
elsif (options.consumer_app_version.nil? || options.consumer_app_version == '' || options.consumer_app_version == 'consumer_app_version') && !options.auto_detect_version_properties
raise Thor::Error.new("ERROR: --consumer-app-version was not provided a value and --auto-detect-version-properties not set")
else
options.consumer_app_version
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/client/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def self.execute_git_commit_command(raise_error)
raise PactBroker::Client::Error,
"Could not determine current git commit using command `#{COMMIT_COMMAND}`. #{e.class} #{e.message}"
else
return nil
return []
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/client/tasks/publication_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def branch= branch
end

def consumer_version=(consumer_version)
@version_required = version_required || !!consumer_version
@version_required = !!consumer_version
@consumer_version = consumer_version
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module PactBroker::Client::CLI
context "with --auto-detect-version-properties on by default" do
before do
subject.options = OpenStruct.new(
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: '')
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
)
allow(subject).to receive(:explict_auto_detect_version_properties).and_return(false)
end
Expand Down Expand Up @@ -203,7 +203,7 @@ module PactBroker::Client::CLI
context "with --auto-detect-version-properties specified explicitly" do
before do
subject.options = OpenStruct.new(
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: '')
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
)
allow(subject).to receive(:explict_auto_detect_version_properties).and_return(true)
end
Expand Down

0 comments on commit 630ab6a

Please sign in to comment.