class PactBroker::Webhooks::PactAndVerificationParameters

Constants

ALL
AZURE_DEV_OPS_VERIFICATION_STATUS
BITBUCKET_VERIFICATION_STATUS
BUILD_URL
CONSUMER_LABELS
CONSUMER_NAME
CONSUMER_VERSION_BRANCH
CONSUMER_VERSION_NUMBER
CONSUMER_VERSION_TAGS
CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER
EVENT_NAME
GITHUB_VERIFICATION_STATUS
GITLAB_VERIFICATION_STATUS
PACT_URL
PROVIDER_LABELS
PROVIDER_NAME
PROVIDER_VERSION_BRANCH
PROVIDER_VERSION_DESCRIPTIONS
PROVIDER_VERSION_NUMBER
PROVIDER_VERSION_TAGS
VERIFICATION_RESULT_URL

Attributes

base_url[R]
pact[R]
verification[R]
webhook_context[R]

Public Class Methods

new(pact, trigger_verification, webhook_context) click to toggle source

TODO change this verification to the latest main branch

# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 48
def initialize(pact, trigger_verification, webhook_context)
  @pact = pact
  @verification = trigger_verification || (pact && pact.latest_verification)
  @webhook_context = webhook_context
  @base_url = webhook_context.fetch(:base_url)
end

Public Instance Methods

to_hash() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 55
def to_hash
  @hash ||= {
    PACT_URL => pact ? PactBroker::Api::PactBrokerUrls.pact_version_url_with_webhook_metadata(pact, base_url) : "",
    VERIFICATION_RESULT_URL => verification_url,
    CONSUMER_VERSION_NUMBER => consumer_version_number,
    PROVIDER_VERSION_NUMBER => provider_version_number,
    PROVIDER_VERSION_TAGS => provider_version_tags,
    PROVIDER_VERSION_BRANCH => provider_version_branch,
    PROVIDER_VERSION_DESCRIPTIONS => provider_version_descriptions,
    CONSUMER_VERSION_TAGS => consumer_version_tags,
    CONSUMER_VERSION_BRANCH => consumer_version_branch,
    CONSUMER_NAME => pact ? pact.consumer_name : "",
    PROVIDER_NAME => pact ? pact.provider_name : "",
    GITHUB_VERIFICATION_STATUS => github_verification_status,
    BITBUCKET_VERIFICATION_STATUS => bitbucket_verification_status,
    AZURE_DEV_OPS_VERIFICATION_STATUS => azure_dev_ops_verification_status,
    GITLAB_VERIFICATION_STATUS => gitlab_verification_status,
    CONSUMER_LABELS => pacticipant_labels(pact && pact.consumer),
    PROVIDER_LABELS => pacticipant_labels(pact && pact.provider),
    EVENT_NAME => event_name,
    BUILD_URL => build_url,
    CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER => currently_deployed_provider_version_number
  }
end

Private Instance Methods

azure_dev_ops_verification_status() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 100
def azure_dev_ops_verification_status
  if verification
    verification.success ? "succeeded" : "failed"
  else
    "pending"
  end
end
bitbucket_verification_status() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 84
def bitbucket_verification_status
  if verification
    verification.success ? "SUCCESSFUL" : "FAILED"
  else
    "INPROGRESS"
  end
end
build_url() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 192
def build_url
  webhook_context[:build_url] || ""
end
consumer_version_branch() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 144
def consumer_version_branch
  if webhook_context.key?(:consumer_version_branch)
    webhook_context[:consumer_version_branch] || ""
  else
    pact&.consumer_version_branch_names&.last || ""
  end
end
consumer_version_number() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 124
def consumer_version_number
  if webhook_context[:consumer_version_number]
    webhook_context[:consumer_version_number]
  else
    pact ? pact.consumer_version_number : ""
  end
end
consumer_version_tags() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 132
def consumer_version_tags
  if webhook_context[:consumer_version_tags]
    webhook_context[:consumer_version_tags].join(", ")
  else
    if pact
      pact.consumer_version_tag_names.join(", ")
    else
      ""
    end
  end
end
currently_deployed_provider_version_number() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 196
def currently_deployed_provider_version_number
  webhook_context[:currently_deployed_provider_version_number] || ""
end
event_name() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 188
def event_name
  webhook_context.fetch(:event_name)
end
github_verification_status() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 92
def github_verification_status
  if verification
    verification.success ? "success" : "failure"
  else
    "pending"
  end
end
gitlab_verification_status() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 108
def gitlab_verification_status
  if verification
    verification.success ? "success" : "failed"
  else
    "pending"
  end
end
pacticipant_labels(pacticipant) click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 184
def pacticipant_labels pacticipant
  pacticipant && pacticipant.labels ? pacticipant.labels.collect(&:name).join(", ") : ""
end
provider_version_branch() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 172
def provider_version_branch
  if webhook_context.key?(:provider_version_branch)
    webhook_context[:provider_version_branch] || ""
  else
    verification&.provider_version&.branch_names&.last || ""
  end
end
provider_version_descriptions() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 180
def provider_version_descriptions
  webhook_context[:provider_version_descriptions]&.join(", ") || ""
end
provider_version_number() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 164
def provider_version_number
  if webhook_context[:provider_version_number]
    webhook_context[:provider_version_number]
  else
    verification ? verification.provider_version_number : ""
  end
end
provider_version_tags() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 152
def provider_version_tags
  if webhook_context[:provider_version_tags]
    webhook_context[:provider_version_tags].join(", ")
  else
    if verification
      verification.provider_version.tags.collect(&:name).join(", ")
    else
      ""
    end
  end
end
verification_url() click to toggle source
# File lib/pact_broker/webhooks/pact_and_verification_parameters.rb, line 116
def verification_url
  if verification
    PactBroker::Api::PactBrokerUrls.verification_url(verification, base_url)
  else
    ""
  end
end