Class: PactBroker::Versions::BranchVersionRepository

Inherits:
Object
  • Object
show all
Includes:
Repositories, Services
Defined in:
lib/pact_broker/versions/branch_version_repository.rb

Constant Summary

Constants included from Repositories

Repositories::REPOSITORY_FACTORIES

Constants included from Services

Services::SERVICE_FACTORIES

Instance 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

Instance Method Details

#add_branch(version, branch_name, auto_created: false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pact_broker/versions/branch_version_repository.rb', line 23

def add_branch(version, branch_name, auto_created: false)
  branch = find_or_create_branch(version.pacticipant, branch_name)
  branch_version = version.branch_version_for_branch(branch)
  if branch_version
    branch_version.update(updated_at: Sequel.datetime_class.now)
  else
    branch_version = PactBroker::Versions::BranchVersion.new(version: version, branch: branch, auto_created: auto_created).insert_ignore
    PactBroker::Versions::BranchHead.new(branch: branch, branch_version: branch_version).upsert
  end
  pacticipant_service.maybe_set_main_branch(version.pacticipant, branch_name)
  branch_version
end

#delete_branch_version(branch_version) ⇒ Object

Deletes a branch version - that is, removes a version from a branch. Updates the branch head if the deleted branch version was the latest for the branch.

Parameters:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pact_broker/versions/branch_version_repository.rb', line 40

def delete_branch_version(branch_version)
  latest = branch_version.latest?
  branch = branch_version.latest? ? branch_version.branch : nil
  deleted = branch_version.delete
  if latest
    new_head_branch_version = BranchVersion.find_latest_for_branch(branch)
    if new_head_branch_version
      PactBroker::Versions::BranchHead.new(branch: branch, branch_version: new_head_branch_version).upsert
    end
  end
  deleted
end

#find_branch_version(pacticipant_name:, branch_name:, version_number:) ⇒ Object



10
11
12
13
14
15
# File 'lib/pact_broker/versions/branch_version_repository.rb', line 10

def find_branch_version(pacticipant_name:, branch_name:, version_number:, **)
  BranchVersion.where(
    version: PactBroker::Domain::Version.where_pacticipant_name_and_version_number(pacticipant_name, version_number),
    branch: Branch.where(name: branch_name)
  ).single_record
end

#find_or_create_branch_version(pacticipant_name:, branch_name:, version_number:) ⇒ Object



17
18
19
20
21
# File 'lib/pact_broker/versions/branch_version_repository.rb', line 17

def find_or_create_branch_version(pacticipant_name:, branch_name:, version_number:, **)
  pacticipant = pacticipant_repository.find_by_name_or_create(pacticipant_name)
  version = version_repository.find_by_pacticipant_id_and_number_or_create(pacticipant.id, version_number)
  branch_version_repository.add_branch(version, branch_name)
end