Class: PactBroker::Pacticipants::Service

Inherits:
Object
  • Object
show all
Extended by:
Messages, Repositories, Services
Includes:
Logging
Defined in:
lib/pact_broker/pacticipants/service.rb

Constant Summary

Constants included from Repositories

Repositories::REPOSITORY_FACTORIES

Constants included from Services

Services::SERVICE_FACTORIES

Class Method Summary collapse

Methods included from Repositories

branch_repository, branch_version_repository, get_repository, integration_repository, label_repository, matrix_repository, pact_repository, pacticipant_repository, register_default_repositories, register_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_service, 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 Messages

message, pluralize, validation_message, validation_message_at_index

Methods included from Logging

included, #log_error, #log_with_tag, #measure_info

Class Method Details

.create(params) ⇒ Object



75
76
77
# File 'lib/pact_broker/pacticipants/service.rb', line 75

def self.create(params)
  pacticipant_repository.create(params)
end

.delete(name) ⇒ Object



83
84
85
86
87
# File 'lib/pact_broker/pacticipants/service.rb', line 83

def self.delete(name)
  pacticipant = find_pacticipant_by_name name
  webhook_service.delete_all_webhhook_related_objects_by_pacticipant(pacticipant)
  pacticipant_repository.delete(pacticipant)
end

.delete_if_orphan(pacticipant) ⇒ Object



89
90
91
# File 'lib/pact_broker/pacticipants/service.rb', line 89

def self.delete_if_orphan(pacticipant)
  pacticipant_repository.delete_if_orphan(pacticipant)
end

.find(options, pagination_options = {}) ⇒ Object



58
59
60
# File 'lib/pact_broker/pacticipants/service.rb', line 58

def self.find(options, pagination_options = {})
  pacticipant_repository.find(options, pagination_options)
end

.find_all_pacticipants(filter_options = {}, pagination_options = {}, eager_load_associations = []) ⇒ Object



35
36
37
# File 'lib/pact_broker/pacticipants/service.rb', line 35

def self.find_all_pacticipants(filter_options = {}, pagination_options = {}, eager_load_associations = [])
  pacticipant_repository.find_all(filter_options, pagination_options, eager_load_associations)
end

.find_by_id(id) ⇒ Object



54
55
56
# File 'lib/pact_broker/pacticipants/service.rb', line 54

def self.find_by_id(id)
  pacticipant_repository.find_by_id(id)
end

.find_pacticipant_by_name(name) ⇒ Object



39
40
41
# File 'lib/pact_broker/pacticipants/service.rb', line 39

def self.find_pacticipant_by_name(name)
  pacticipant_repository.find_by_name(name)
end

.find_pacticipant_by_name!(name) ⇒ Object



50
51
52
# File 'lib/pact_broker/pacticipants/service.rb', line 50

def self.find_pacticipant_by_name!(name)
  pacticipant_repository.find_by_name!(name)
end

.find_pacticipant_repository_url_by_pacticipant_name(name) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/pact_broker/pacticipants/service.rb', line 62

def self.find_pacticipant_repository_url_by_pacticipant_name(name)
  pacticipant = pacticipant_repository.find_by_name(name)
  if pacticipant && pacticipant.repository_url
    pacticipant.repository_url
  else
    nil
  end
end

.find_pacticipants_by_names(names) ⇒ Array<PactBroker::Domain::Pacticipant>

Used by pf

Parameters:

  • (Array<String>)

Returns:



46
47
48
# File 'lib/pact_broker/pacticipants/service.rb', line 46

def self.find_pacticipants_by_names(names)
  pacticipant_repository.find_by_names(names)
end

.find_potential_duplicate_pacticipants(pacticipant_name) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/pact_broker/pacticipants/service.rb', line 26

def self.find_potential_duplicate_pacticipants pacticipant_name
  PactBroker::Pacticipants::FindPotentialDuplicatePacticipantNames
    .call(pacticipant_name, pacticipant_names).tap { | names|
      if names.any?
        logger.info "The following potential duplicate pacticipants were found for #{pacticipant_name}: #{names.join(", ")}"
      end
    } .collect{ | name | pacticipant_repository.find_by_name(name) }
end

.maybe_set_main_branch(pacticipant, potential_main_branch) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/pact_broker/pacticipants/service.rb', line 97

def self.maybe_set_main_branch(pacticipant, potential_main_branch)
  if pacticipant.main_branch.nil? && PactBroker.configuration.auto_detect_main_branch && PactBroker.configuration.main_branch_candidates.include?(potential_main_branch)
    logger.info "Setting #{pacticipant.name} main_branch to '#{potential_main_branch}' (because the #{pacticipant.name} main_branch was nil and auto_detect_main_branch=true)"
    pacticipant_repository.set_main_branch(pacticipant, potential_main_branch)
  else
    pacticipant
  end
end

.messages_for_potential_duplicate_pacticipants(pacticipant_names, base_url) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/pact_broker/pacticipants/service.rb', line 15

def self.messages_for_potential_duplicate_pacticipants(pacticipant_names, base_url)
  messages = []
  pacticipant_names.each do | name |
    potential_duplicate_pacticipants = find_potential_duplicate_pacticipants(name)
    if potential_duplicate_pacticipants.any?
      messages << potential_duplicate_pacticipant_message(name, potential_duplicate_pacticipants, base_url)
    end
  end
  messages
end

.pacticipant_namesObject



93
94
95
# File 'lib/pact_broker/pacticipants/service.rb', line 93

def self.pacticipant_names
  pacticipant_repository.pacticipant_names
end

.replace(pacticipant_name, open_struct_pacticipant) ⇒ Object



79
80
81
# File 'lib/pact_broker/pacticipants/service.rb', line 79

def self.replace(pacticipant_name, open_struct_pacticipant)
  pacticipant_repository.replace(pacticipant_name, open_struct_pacticipant)
end

.update(pacticipant_name, pacticipant) ⇒ Object



71
72
73
# File 'lib/pact_broker/pacticipants/service.rb', line 71

def self.update(pacticipant_name, pacticipant)
  pacticipant_repository.update(pacticipant_name, pacticipant)
end