pact_broker-client 1.41.0 → 1.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +21 -0
  3. data/CHANGELOG.md +57 -0
  4. data/README.md +69 -48
  5. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -102
  6. data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +94 -0
  7. data/doc/pacts/markdown/README.md +1 -0
  8. data/lib/pact_broker/client/backports.rb +9 -0
  9. data/lib/pact_broker/client/base_command.rb +98 -0
  10. data/lib/pact_broker/client/can_i_deploy.rb +40 -5
  11. data/lib/pact_broker/client/cli/broker.rb +18 -160
  12. data/lib/pact_broker/client/cli/custom_thor.rb +12 -16
  13. data/lib/pact_broker/client/cli/deployment_commands.rb +94 -0
  14. data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
  15. data/lib/pact_broker/client/cli/pacticipant_commands.rb +53 -0
  16. data/lib/pact_broker/client/cli/webhook_commands.rb +122 -0
  17. data/lib/pact_broker/client/deployments.rb +4 -0
  18. data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
  19. data/lib/pact_broker/client/deployments/record_release.rb +99 -0
  20. data/lib/pact_broker/client/deployments/record_support_ended.rb +103 -0
  21. data/lib/pact_broker/client/deployments/record_undeployment.rb +127 -0
  22. data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
  23. data/lib/pact_broker/client/environments.rb +6 -0
  24. data/lib/pact_broker/client/environments/create_environment.rb +31 -0
  25. data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
  26. data/lib/pact_broker/client/environments/describe_environment.rb +26 -0
  27. data/lib/pact_broker/client/environments/environment_command.rb +66 -0
  28. data/lib/pact_broker/client/environments/list_environments.rb +30 -0
  29. data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
  30. data/lib/pact_broker/client/environments/update_environment.rb +31 -0
  31. data/lib/pact_broker/client/generate_display_name.rb +27 -0
  32. data/lib/pact_broker/client/hal/entity.rb +31 -6
  33. data/lib/pact_broker/client/hal/http_client.rb +8 -2
  34. data/lib/pact_broker/client/hal/link.rb +8 -0
  35. data/lib/pact_broker/client/hal_client_methods.rb +1 -3
  36. data/lib/pact_broker/client/matrix/text_formatter.rb +21 -13
  37. data/lib/pact_broker/client/pacticipants.rb +6 -0
  38. data/lib/pact_broker/client/pacticipants/create.rb +24 -34
  39. data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
  40. data/lib/pact_broker/client/pacticipants/list.rb +34 -0
  41. data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
  42. data/lib/pact_broker/client/string_refinements.rb +56 -0
  43. data/lib/pact_broker/client/version.rb +1 -1
  44. data/lib/pact_broker/client/versions.rb +4 -1
  45. data/lib/pact_broker/client/versions/describe.rb +3 -1
  46. data/lib/pact_broker/client/versions/formatter.rb +3 -1
  47. data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
  48. data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
  49. data/lib/pact_broker/client/webhooks/create.rb +14 -8
  50. data/pact-broker-client.gemspec +1 -0
  51. data/script/record-deployments-and-releases.sh +18 -0
  52. data/script/webhook-commands.sh +12 -0
  53. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +7 -0
  54. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +7 -0
  55. data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
  56. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
  57. data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
  58. data/spec/integration/describe_environment_spec.rb +31 -0
  59. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +62 -2
  60. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +17 -4
  61. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
  62. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +7 -5
  63. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
  64. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +208 -0
  65. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +219 -0
  66. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
  67. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
  68. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
  69. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
  70. data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
  71. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
  72. data/spec/pacts/pact_broker_client-pact_broker.json +88 -108
  73. data/spec/pacts/pact_broker_client-pactflow.json +118 -0
  74. data/spec/service_providers/create_environment_spec.rb +78 -0
  75. data/spec/service_providers/list_environments_spec.rb +77 -0
  76. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +1 -1
  77. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +2 -2
  78. data/spec/service_providers/pact_helper.rb +15 -10
  79. data/spec/service_providers/pactflow_webhooks_create_spec.rb +86 -0
  80. data/spec/service_providers/pacticipants_create_spec.rb +5 -4
  81. data/spec/service_providers/publish_pacts_spec.rb +3 -1
  82. data/spec/service_providers/record_deployment_spec.rb +14 -32
  83. data/spec/service_providers/record_release_spec.rb +132 -0
  84. data/spec/service_providers/record_undeployment_spec.rb +166 -0
  85. data/spec/service_providers/webhooks_create_spec.rb +1 -1
  86. data/spec/spec_helper.rb +15 -2
  87. data/spec/support/approvals.rb +1 -1
  88. data/spec/support/shared_context.rb +2 -1
  89. data/tasks/pact.rake +21 -1
  90. metadata +82 -7
  91. data/lib/pact_broker/client/versions/record_deployment.rb +0 -109
  92. data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
  93. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -82
@@ -91,25 +91,21 @@ module PactBroker
91
91
  method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
92
92
  end
93
93
 
94
- def self.shared_options_for_webhook_commands
95
- method_option :request, banner: "METHOD", aliases: "-X", desc: "Webhook HTTP method", required: true
96
- method_option :header, aliases: "-H", type: :array, desc: "Webhook Header"
97
- method_option :data, aliases: "-d", desc: "Webhook payload (file or string)"
98
- method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
99
- method_option :consumer, desc: "Consumer name"
100
- method_option :provider, desc: "Provider name"
101
- method_option :description, desc: "Wwebhook description"
102
- method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
103
- method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
104
- method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
105
- method_option :provider_verification_failed, type: :boolean, desc: "Trigger this webhook when a failed provider verification result is published"
106
- method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
107
- shared_authentication_options
108
- end
109
-
110
94
  def self.verbose_option
111
95
  method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
112
96
  end
97
+
98
+ def self.output_option_json_or_text
99
+ method_option :output, aliases: "-o", desc: "json or text", default: 'text'
100
+ end
101
+
102
+ def self.output_option_json_or_table
103
+ method_option :output, aliases: "-o", desc: "json or table", default: 'table'
104
+ end
105
+
106
+ def params_from_options(keys)
107
+ keys.each_with_object({}) { | key, p | p[key] = options[key] }
108
+ end
113
109
  end
114
110
  end
115
111
  end
@@ -0,0 +1,94 @@
1
+ module PactBroker
2
+ module Client
3
+ module CLI
4
+ module DeploymentCommands
5
+ RECORD_DEPLOYMENT_HELP_URL = "https://docs.pact.io/go/record-deployment"
6
+ RECORD_UNDEPLOYMENT_HELP_URL = "https://docs.pact.io/go/record-undeployment"
7
+ RECORD_RELEASE_HELP_URL = "https://docs.pact.io/go/record-release"
8
+ RECORD_SUPPORT_ENDED_HELP_URL = "https://docs.pact.io/go/record-support-ended"
9
+
10
+
11
+ def self.included(thor)
12
+ thor.class_eval do
13
+ desc "record-deployment", "Record deployment of a pacticipant version to an environment. See #{RECORD_DEPLOYMENT_HELP_URL} for more information."
14
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
15
+ method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
16
+ method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
17
+ method_option :target, default: nil, required: false, desc: "Optional. The target of the deployment - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
18
+ output_option_json_or_text
19
+ shared_authentication_options
20
+
21
+ def record_deployment
22
+ params = {
23
+ pacticipant_name: options.pacticipant,
24
+ version_number: options.version,
25
+ environment_name: options.environment,
26
+ target: options.target
27
+ }
28
+ execute_deployment_command(params, "RecordDeployment")
29
+ end
30
+
31
+ desc "record-undeployment", "Record undeployment of a pacticipant from an environment."
32
+ long_desc "Note that use of this command is only required if you are permanently removing an application instance from an environment. It is not required if you are deploying over a previous version, as record-deployment will automatically mark the previously deployed version as undeployed for you. See #{RECORD_UNDEPLOYMENT_HELP_URL} for more information."
33
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was undeployed."
34
+ method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was undeployed from."
35
+ method_option :target, default: nil, required: false, desc: "Optional. The target that the application is being undeployed from - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
36
+ output_option_json_or_text
37
+ shared_authentication_options
38
+
39
+ def record_undeployment
40
+ params = {
41
+ pacticipant_name: options.pacticipant,
42
+ environment_name: options.environment,
43
+ target: options.target
44
+ }
45
+ execute_deployment_command(params, "RecordUndeployment")
46
+ end
47
+
48
+ desc "record-release", "Record release of a pacticipant version to an environment. See See #{RECORD_RELEASE_HELP_URL} for more information."
49
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was released."
50
+ method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was released."
51
+ method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was released to."
52
+ output_option_json_or_text
53
+ shared_authentication_options
54
+
55
+ def record_release
56
+ params = {
57
+ pacticipant_name: options.pacticipant,
58
+ version_number: options.version,
59
+ environment_name: options.environment
60
+ }
61
+ execute_deployment_command(params, "RecordRelease")
62
+ end
63
+
64
+ desc "record-support-ended", "Record the end of support for a pacticipant version in an environment. See #{RECORD_SUPPORT_ENDED_HELP_URL} for more information."
65
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant."
66
+ method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number for which support is ended."
67
+ method_option :environment, required: true, desc: "The name of the environment in which the support is ended."
68
+ output_option_json_or_text
69
+ shared_authentication_options
70
+
71
+ def record_support_ended
72
+ params = {
73
+ pacticipant_name: options.pacticipant,
74
+ version_number: options.version,
75
+ environment_name: options.environment
76
+ }
77
+ execute_deployment_command(params, "RecordSupportEnded")
78
+ end
79
+
80
+ no_commands do
81
+ def execute_deployment_command(params, command_class_name)
82
+ require 'pact_broker/client/deployments'
83
+ command_options = { verbose: options.verbose, output: options.output }
84
+ result = PactBroker::Client::Deployments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
85
+ $stdout.puts result.message
86
+ exit(1) unless result.success
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,70 @@
1
+ module PactBroker
2
+ module Client
3
+ module CLI
4
+ module EnvironmentCommands
5
+ ENVIRONMENT_PARAM_NAMES = [:name, :display_name, :production, :contact_name, :contact_email_address]
6
+
7
+ def self.included(thor)
8
+ thor.class_eval do
9
+ def self.shared_environment_options(name_required: false)
10
+ method_option :name, required: name_required, desc: "The uniquely identifying name of the environment as used in deployment code"
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. Default: false"
13
+ method_option :contact_name, required: false, desc: "The name of the team/person responsible for this environment"
14
+ method_option :contact_email_address, required: false, desc: "The email address of the team/person responsible for this environment"
15
+ output_option_json_or_text
16
+ end
17
+
18
+ desc "create-environment", "Create an environment resource in the Pact Broker to represent a real world deployment or release environment."
19
+ shared_environment_options(name_required: true)
20
+ shared_authentication_options
21
+ def create_environment
22
+ execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES), "CreateEnvironment")
23
+ end
24
+
25
+ desc "update-environment", "Update an environment resource in the Pact Broker."
26
+ method_option :uuid, required: true, desc: "The UUID of the environment to update"
27
+ shared_environment_options(name_required: false)
28
+ shared_authentication_options
29
+ def update_environment
30
+ execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES + [:uuid]), "UpdateEnvironment")
31
+ end
32
+
33
+ desc "describe-environment", "Describe an environment"
34
+ method_option :uuid, required: true, desc: "The UUID of the environment to describe"
35
+ method_option :output, aliases: "-o", desc: "json or text", default: 'text'
36
+ shared_authentication_options
37
+ def describe_environment
38
+ execute_environment_command(params_from_options([:uuid]), "DescribeEnvironment")
39
+ end
40
+
41
+ desc "list-environments", "List environment"
42
+ method_option :output, aliases: "-o", desc: "json or text", default: 'text'
43
+ shared_authentication_options
44
+ def list_environments
45
+ execute_environment_command({}, "ListEnvironments")
46
+ end
47
+
48
+ desc "delete-environment", "Delete an environment"
49
+ method_option :uuid, required: true, desc: "The UUID of the environment to delete"
50
+ method_option :output, aliases: "-o", desc: "json or text", default: 'text'
51
+ shared_authentication_options
52
+ def delete_environment
53
+ execute_environment_command(params_from_options([:uuid]), "DeleteEnvironment")
54
+ end
55
+
56
+ no_commands do
57
+ def execute_environment_command(params, command_class_name)
58
+ require 'pact_broker/client/environments'
59
+ command_options = { verbose: options.verbose, output: options.output }
60
+ result = PactBroker::Client::Environments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
61
+ $stdout.puts result.message
62
+ exit(1) unless result.success
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,53 @@
1
+ module PactBroker
2
+ module Client
3
+ module CLI
4
+ module PacticipantCommands
5
+ PACTICIPANT_PARAM_NAMES = [:name, :display_name, :repository_url]
6
+
7
+ def self.included(thor)
8
+ thor.class_eval do
9
+ desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
10
+ method_option :name, type: :string, required: true, desc: "Pacticipant name"
11
+ method_option :display_name, type: :string, desc: "Display name"
12
+ method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
13
+ output_option_json_or_text
14
+ shared_authentication_options
15
+ verbose_option
16
+
17
+ def create_or_update_pacticipant(*required_but_ignored)
18
+ raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
19
+ execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'Create')
20
+ end
21
+
22
+ desc 'list-pacticipants', 'List pacticipants'
23
+ output_option_json_or_text
24
+ shared_authentication_options
25
+ verbose_option
26
+ def list_pacticipants
27
+ execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'List')
28
+ end
29
+
30
+ desc 'describe-pacticipant', "Describe a pacticipant"
31
+ method_option :name, type: :string, required: true, desc: "Pacticipant name"
32
+ output_option_json_or_text
33
+ shared_authentication_options
34
+ verbose_option
35
+ def describe_pacticipant
36
+ execute_pacticipant_command({ name: options.name }, 'Describe')
37
+ end
38
+
39
+ no_commands do
40
+ def execute_pacticipant_command(params, command_class_name)
41
+ require 'pact_broker/client/pacticipants'
42
+ command_options = { verbose: options.verbose, output: options.output }
43
+ result = PactBroker::Client::Pacticipants2.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
44
+ $stdout.puts result.message
45
+ exit(1) unless result.success
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,122 @@
1
+ module PactBroker
2
+ module Client
3
+ module CLI
4
+ # Thor::Error will have its backtrace hidden
5
+ class WebhookCreationError < ::Thor::Error; end
6
+
7
+ module WebhookCommands
8
+ def self.included(thor)
9
+ thor.class_eval do
10
+
11
+ no_commands do
12
+ def self.shared_options_for_webhook_commands
13
+ method_option :request, banner: "METHOD", aliases: "-X", desc: "Webhook HTTP method", required: true
14
+ method_option :header, aliases: "-H", type: :array, desc: "Webhook Header"
15
+ method_option :data, aliases: "-d", desc: "Webhook payload (file or string)"
16
+ method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
17
+ method_option :consumer, desc: "Consumer name"
18
+ method_option :provider, desc: "Provider name"
19
+ method_option :description, desc: "Webhook description"
20
+ method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
21
+ method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
22
+ method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
23
+ method_option :provider_verification_failed, type: :boolean, desc: "Trigger this webhook when a failed provider verification result is published"
24
+ method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
25
+ method_option :team_uuid, banner: "UUID", desc: "UUID of the Pactflow team to which the webhook should be assigned (Pactflow only)"
26
+ shared_authentication_options
27
+ end
28
+ end
29
+
30
+ shared_options_for_webhook_commands
31
+
32
+ desc 'create-webhook URL', 'Creates a webhook using the same switches as a curl request.'
33
+ long_desc File.read(File.join(File.dirname(__FILE__), 'create_webhook_long_desc.txt'))
34
+ def create_webhook webhook_url
35
+ run_webhook_commands webhook_url
36
+ end
37
+
38
+ shared_options_for_webhook_commands
39
+ method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
40
+
41
+ desc 'create-or-update-webhook URL', 'Creates or updates a webhook with a provided uuid and using the same switches as a curl request.'
42
+ long_desc File.read(File.join(File.dirname(__FILE__), 'create_or_update_webhook_long_desc.txt'))
43
+ def create_or_update_webhook webhook_url
44
+ run_webhook_commands webhook_url
45
+ end
46
+
47
+ desc 'test-webhook', 'Test the execution of a webhook'
48
+ method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
49
+ shared_authentication_options
50
+ def test_webhook
51
+ require 'pact_broker/client/webhooks/test'
52
+ result = PactBroker::Client::Webhooks::Test.call(options, pact_broker_client_options)
53
+ $stdout.puts result.message
54
+ end
55
+
56
+ no_commands do
57
+
58
+ def parse_webhook_events
59
+ events = []
60
+ events << 'contract_content_changed' if options.contract_content_changed
61
+ events << 'contract_published' if options.contract_published
62
+ events << 'provider_verification_published' if options.provider_verification_published
63
+ events << 'provider_verification_succeeded' if options.provider_verification_succeeded
64
+ events << 'provider_verification_failed' if options.provider_verification_failed
65
+ events
66
+ end
67
+
68
+ def parse_webhook_options(webhook_url)
69
+ events = parse_webhook_events
70
+
71
+ if events.size == 0
72
+ raise WebhookCreationError.new("You must specify at least one of --contract-content-changed, --contract-published, --provider-verification-published, --provider-verification-succeeded or --provider-verification-failed")
73
+ end
74
+
75
+ username = options.user ? options.user.split(":", 2).first : nil
76
+ password = options.user ? options.user.split(":", 2).last : nil
77
+
78
+ headers = (options.header || []).each_with_object({}) { | header, headers | headers[header.split(":", 2).first.strip] = header.split(":", 2).last.strip }
79
+
80
+ body = options.data
81
+ if body && body.start_with?("@")
82
+ filepath = body[1..-1]
83
+ begin
84
+ body = File.read(filepath)
85
+ rescue StandardError => e
86
+ raise WebhookCreationError.new("Couldn't read data from file \"#{filepath}\" due to #{e.class} #{e.message}")
87
+ end
88
+ end
89
+
90
+ {
91
+ uuid: options.uuid,
92
+ description: options.description,
93
+ http_method: options.request,
94
+ url: webhook_url,
95
+ headers: headers,
96
+ username: username,
97
+ password: password,
98
+ body: body,
99
+ consumer: options.consumer,
100
+ provider: options.provider,
101
+ events: events,
102
+ team_uuid: options.team_uuid
103
+ }
104
+ end
105
+
106
+ def run_webhook_commands webhook_url
107
+ require 'pact_broker/client/webhooks/create'
108
+
109
+ validate_credentials
110
+ result = PactBroker::Client::Webhooks::Create.call(parse_webhook_options(webhook_url), options.broker_base_url, pact_broker_client_options)
111
+ $stdout.puts result.message
112
+ exit(1) unless result.success
113
+ rescue PactBroker::Client::Error => e
114
+ raise WebhookCreationError, "#{e.class} - #{e.message}"
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,4 @@
1
+ require "pact_broker/client/deployments/record_deployment"
2
+ require "pact_broker/client/deployments/record_release"
3
+ require "pact_broker/client/deployments/record_undeployment"
4
+ require "pact_broker/client/deployments/record_support_ended"
@@ -0,0 +1,38 @@
1
+ require 'pact_broker/client/deployments/record_release'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Deployments
6
+ class RecordDeployment < PactBroker::Client::Deployments::RecordRelease
7
+ def initialize(params, options, pact_broker_client_options)
8
+ super
9
+ @target = params.fetch(:target)
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :target
15
+
16
+ def action
17
+ "deployment"
18
+ end
19
+
20
+ def action_relation_name
21
+ "pb:record-deployment"
22
+ end
23
+
24
+ def record_action_request_body
25
+ { target: target }.compact
26
+ end
27
+
28
+ def result_text_message
29
+ if target
30
+ "#{super} (target #{target})"
31
+ else
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,99 @@
1
+ require 'pact_broker/client/base_command'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Deployments
6
+ class RecordRelease < PactBroker::Client::BaseCommand
7
+ def initialize(params, options, pact_broker_client_options)
8
+ super
9
+ @pacticipant_name = params.fetch(:pacticipant_name)
10
+ @version_number = params.fetch(:version_number)
11
+ @environment_name = params.fetch(:environment_name)
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :pacticipant_name, :version_number, :environment_name
17
+ attr_reader :deployed_version_resource
18
+
19
+ def do_call
20
+ record_action
21
+ PactBroker::Client::CommandResult.new(true, result_message)
22
+ end
23
+
24
+ def action
25
+ "release"
26
+ end
27
+
28
+ def action_relation_name
29
+ "pb:record-release"
30
+ end
31
+
32
+ def not_supported_message
33
+ "This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later."
34
+ end
35
+
36
+ def environment_exists?
37
+ index_resource
38
+ ._link!("pb:environments")
39
+ .get!
40
+ ._links("pb:environments")
41
+ .find(environment_name)
42
+ end
43
+
44
+ def record_action
45
+ @deployed_version_resource =
46
+ get_record_action_relation
47
+ .post(record_action_request_body)
48
+ .assert_success!
49
+ end
50
+
51
+ def record_action_links
52
+ get_pacticipant_version._links(action_relation_name) or raise PactBroker::Client::Error.new(not_supported_message)
53
+ end
54
+
55
+ def get_record_action_relation
56
+ record_action_links.find(environment_name) or record_action_links.find!(environment_name, environment_relation_not_found_error_message)
57
+ end
58
+
59
+ def environment_relation_not_found_error_message
60
+ if environment_exists?
61
+ "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}."
62
+ else
63
+ "No environment found with name '#{environment_name}'."
64
+ end
65
+ end
66
+
67
+ def get_pacticipant_version
68
+ index_resource
69
+ ._link!("pb:pacticipant-version")
70
+ .expand(pacticipant: pacticipant_name, version: version_number)
71
+ .get
72
+ .assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
73
+ end
74
+
75
+ def record_action_request_body
76
+ {}
77
+ end
78
+
79
+ def result_message
80
+ if json_output?
81
+ deployed_version_resource.response.raw_body
82
+ else
83
+ green("#{result_text_message} in #{pact_broker_name}.")
84
+ end
85
+ end
86
+
87
+ def result_text_message
88
+ "Recorded #{action} of #{pacticipant_name} version #{version_number} to #{environment_name} environment"
89
+ end
90
+
91
+ def check_if_command_supported
92
+ unless index_resource.can?("pb:environments")
93
+ raise PactBroker::Client::Error.new(not_supported_message)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end