Module: PactBroker::Matrix::Service
- Extended by:
- Service, PactBroker::Messages, Repositories, Services
- Includes:
- Logging
- Included in:
- Service
- Defined in:
- lib/pact_broker/matrix/service.rb
Constant Summary
Constants included from Services
Instance Method Summary collapse
- #can_i_deploy(selectors, options = {}) ⇒ Object
- #find(selectors, options = {}) ⇒ Object
- #find_for_consumer_and_provider(params, options = {}) ⇒ Object
- #find_for_consumer_and_provider_with_tags(params) ⇒ Object
-
#validate_selectors(selectors, options = {}) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength.
Methods included from Repositories
branch_version_repository, integration_repository, label_repository, matrix_repository, pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Services
badge_service, branch_service, certificate_service, contract_service, deployed_version_service, environment_service, get, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, register_default_services, register_service, released_version_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service
Methods included from PactBroker::Messages
message, pluralize, potential_duplicate_pacticipant_message, validation_message
Methods included from Logging
included, #log_error, #log_with_tag
Instance Method Details
#can_i_deploy(selectors, options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/pact_broker/matrix/service.rb', line 20 def can_i_deploy(selectors, = {}) # No point doing the deployment status summary if no versions are specified. query_results = find(selectors, ) QueryResultsWithDeploymentStatusSummary.new(query_results, DeploymentStatusSummary.new(query_results)) end |
#find(selectors, options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/pact_broker/matrix/service.rb', line 26 def find selectors, = {} logger.info "Querying matrix", selectors: selectors, options: matrix_repository.find(selectors, ) end |
#find_for_consumer_and_provider(params, options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/pact_broker/matrix/service.rb', line 31 def find_for_consumer_and_provider params, = {} selectors = [ UnresolvedSelector.new(pacticipant_name: params[:consumer_name]), UnresolvedSelector.new(pacticipant_name: params[:provider_name]) ] can_i_deploy(selectors, ) end |
#find_for_consumer_and_provider_with_tags(params) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pact_broker/matrix/service.rb', line 36 def params consumer_selector = UnresolvedSelector.new( pacticipant_name: params[:consumer_name], tag: params[:tag], latest: true ) provider_selector = UnresolvedSelector.new( pacticipant_name: params[:provider_name], tag: params[:provider_tag], latest: true ) selectors = [consumer_selector, provider_selector] = { latestby: "cvpv" } if validate_selectors(selectors).empty? matrix_repository.find(selectors, ).first else nil end end |
#validate_selectors(selectors, options = {}) ⇒ Object
rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pact_broker/matrix/service.rb', line 57 def validate_selectors selectors, = {} = [] selectors.each do | s | if s[:pacticipant_name].nil? << "Please specify the pacticipant name" else # TODO a bunch more validation if s.key?(:pacticipant_version_number) && s.key?(:latest) << "A version number and latest flag cannot both be specified for #{s[:pacticipant_name]}" end end end selectors.collect{ |selector| selector[:pacticipant_name] }.compact.each do | pacticipant_name | unless pacticipant_service.find_pacticipant_by_name(pacticipant_name) << "Pacticipant #{pacticipant_name} not found" end end .fetch(:ignore_selectors, []).each do | s | if s[:pacticipant_name].nil? << "Please specify the pacticipant name to ignore" else if s.key?(:pacticipant_version_number) && s.key?(:latest) << "A version number and latest flag cannot both be specified for #{s[:pacticipant_name]} to ignore" end end end if selectors.size == 0 << "Please provide 1 or more version selectors." end if [:tag]&.not_blank? && [:environment_name]&.not_blank? << ("errors.validation.cannot_specify_tag_and_environment") end if [:latest] && [:environment_name]&.not_blank? << ("errors.validation.cannot_specify_latest_and_environment") end if [:environment_name]&.not_blank? && environment_service.find_by_name([:environment_name]).nil? << ("errors.validation.environment_with_name_not_found", name: [:environment_name]) end if [:limit] && [:limit].to_i < 1 << ("errors.validation.invalid_limit") end end |