Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add participant label options to webhook create/update commands #96

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,12 @@ Options:
# Webhook basic auth username and password eg. username:password
[--consumer=CONSUMER]
# Consumer name
[--consumer-label=CONSUMER_LABEL]
# Consumer label
[--provider=PROVIDER]
# Provider name
[--provider-label=PROVIDER_LABEL]
# Provider label
[--description=DESCRIPTION]
# Webhook description
[--contract-content-changed], [--no-contract-content-changed]
Expand Down Expand Up @@ -663,8 +667,12 @@ Options:
# Webhook basic auth username and password eg. username:password
[--consumer=CONSUMER]
# Consumer name
[--consumer-label=CONSUMER_LABEL]
# Consumer label
[--provider=PROVIDER]
# Provider name
[--provider-label=PROVIDER_LABEL]
# Provider label
[--description=DESCRIPTION]
# Webhook description
[--contract-content-changed], [--no-contract-content-changed]
Expand Down
222 changes: 222 additions & 0 deletions doc/pacts/markdown/Pact Broker Client - Pact Broker.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@

* [A request to create a webhook with a JSON body for a consumer and provider](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_and_provider_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker

* [A request to create a webhook with a JSON body for a consumer specified by a label](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_specified_by_a_label)

* [A request to create a webhook with a JSON body for a consumer that does not exist](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_that_does_not_exist)

* [A request to create a webhook with a JSON body for a provider](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker

* [A request to create a webhook with a JSON body for a provider specified by a label](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_specified_by_a_label)

* [A request to create a webhook with a non-JSON body for a consumer and provider](#a_request_to_create_a_webhook_with_a_non-JSON_body_for_a_consumer_and_provider_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker

* [A request to create a webhook with every possible event type](#a_request_to_create_a_webhook_with_every_possible_event_type_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
Expand Down Expand Up @@ -1089,6 +1093,16 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -1222,6 +1236,16 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -1276,6 +1300,16 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -1327,6 +1361,80 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
"title": "A title"
}
}
}
}
```
<a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_specified_by_a_label"></a>
Upon receiving **a request to create a webhook with a JSON body for a consumer specified by a label** from Pact Broker Client, with
```json
{
"method": "post",
"path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
"headers": {
"Content-Type": "application/json",
"Accept": "application/hal+json"
},
"body": {
"description": "a webhook",
"events": [
{
"name": "contract_content_changed"
}
],
"request": {
"url": "https://webhook",
"method": "POST",
"headers": {
"Foo": "bar",
"Bar": "foo"
},
"body": {
"some": "body"
},
"username": "username",
"password": "password"
},
"consumer": {
"label": "consumer_label"
}
}
}
```
Pact Broker will respond with:
```json
{
"status": 201,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -1433,6 +1541,80 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
"title": "A title"
}
}
}
}
```
<a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_specified_by_a_label"></a>
Upon receiving **a request to create a webhook with a JSON body for a provider specified by a label** from Pact Broker Client, with
```json
{
"method": "post",
"path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
"headers": {
"Content-Type": "application/json",
"Accept": "application/hal+json"
},
"body": {
"description": "a webhook",
"events": [
{
"name": "contract_content_changed"
}
],
"request": {
"url": "https://webhook",
"method": "POST",
"headers": {
"Foo": "bar",
"Bar": "foo"
},
"body": {
"some": "body"
},
"username": "username",
"password": "password"
},
"provider": {
"label": "provider_label"
}
}
}
```
Pact Broker will respond with:
```json
{
"status": 201,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -1482,6 +1664,14 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": "<xml></xml>"
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -1545,6 +1735,28 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
},
{
"name": "contract_published"
},
{
"name": "provider_verification_published"
},
{
"name": "provider_verification_succeeded"
},
{
"name": "provider_verification_failed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down Expand Up @@ -2550,6 +2762,16 @@ Pact Broker will respond with:
},
"body": {
"description": "a webhook",
"request": {
"body": {
"some": "body"
}
},
"events": [
{
"name": "contract_content_changed"
}
],
"_links": {
"self": {
"href": "http://localhost:1234/some-url",
Expand Down
17 changes: 16 additions & 1 deletion lib/pact_broker/client/cli/webhook_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def self.shared_options_for_webhook_commands
method_option :data, aliases: "-d", desc: "Webhook payload (file or string)"
method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
method_option :consumer, desc: "Consumer name"
method_option :consumer_label, desc: "Consumer label, mutually exclusive with consumer name"
method_option :provider, desc: "Provider name"
method_option :provider_label, desc: "Provider label, mutually exclusive with provider name"
method_option :description, desc: "Webhook description"
method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
Expand Down Expand Up @@ -70,6 +72,7 @@ def parse_webhook_events
end

def parse_webhook_options(webhook_url)
validate_mutual_exclusiveness_of_participant_name_and_label_options
events = parse_webhook_events

# TODO update for contract_requiring_verification_published when released
Expand Down Expand Up @@ -102,7 +105,9 @@ def parse_webhook_options(webhook_url)
password: password,
body: body,
consumer: options.consumer,
consumer_label: options.consumer_label,
provider: options.provider,
provider_label: options.provider_label,
events: events,
team_uuid: options.team_uuid
}
Expand All @@ -118,10 +123,20 @@ def run_webhook_commands webhook_url
rescue PactBroker::Client::Error => e
raise WebhookCreationError, "#{e.class} - #{e.message}"
end

def validate_mutual_exclusiveness_of_participant_name_and_label_options
if options.consumer && options.consumer_label
raise WebhookCreationError.new("Consumer name (--consumer) and label (--consumer_label) options are mutually exclusive")
end

if options.provider && options.provider_label
raise WebhookCreationError.new("Provider name (--provider) and label (--provider_label) options are mutually exclusive")
end
end
end
end
end
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/pact_broker/client/webhooks/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ def request_body_with_optional_consumer_and_provider

if params.consumer
body[:consumer] = { name: params.consumer }
elsif params.consumer_label
body[:consumer] = { label: params.consumer_label }
end

if params.provider
body[:provider] = { name: params.provider }
elsif params.provider_label
body[:provider] = { label: params.provider_label }
end

if params.team_uuid
Expand Down
Loading