Class: PactBroker::Pacticipants::Service

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

Constant Summary

Constants included from Services

Services::FACTORIES

Class Method Summary collapse

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 Logging

included, #log_error, #log_with_tag

Class Method Details

.create(params) ⇒ Object



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

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

.delete(name) ⇒ Object



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

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



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

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

.find(options) ⇒ Object



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

def self.find(options)
  pacticipant_repository.find options
end

.find_all_pacticipant_versions_in_reverse_order(name, pagination_options = nil) ⇒ Object



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

def self.find_all_pacticipant_versions_in_reverse_order(name, pagination_options = nil)
  pacticipant_repository.find_all_pacticipant_versions_in_reverse_order(name, pagination_options)
end

.find_all_pacticipantsObject



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

def self.find_all_pacticipants
  pacticipant_repository.find_all
end

.find_by_id(id) ⇒ Object



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

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

.find_pacticipant_by_name(name) ⇒ Object



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

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

.find_pacticipant_by_name!(name) ⇒ Object



42
43
44
# File 'lib/pact_broker/pacticipants/service.rb', line 42

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

.find_pacticipant_repository_url_by_pacticipant_name(name) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/pact_broker/pacticipants/service.rb', line 58

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_potential_duplicate_pacticipants(pacticipant_name) ⇒ Object



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

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



93
94
95
96
97
98
99
100
# File 'lib/pact_broker/pacticipants/service.rb', line 93

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



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

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 << Messages.potential_duplicate_pacticipant_message(name, potential_duplicate_pacticipants, base_url)
    end
  end
  messages
end

.pacticipant_namesObject



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

def self.pacticipant_names
  pacticipant_repository.pacticipant_names
end

.replace(pacticipant_name, open_struct_pacticipant) ⇒ Object



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

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

.update(pacticipant_name, pacticipant) ⇒ Object



67
68
69
# File 'lib/pact_broker/pacticipants/service.rb', line 67

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