class PactBroker::Versions::BranchVersionRepository

Public Instance Methods

add_branch(version, branch_name, auto_created: false) click to toggle source
# File lib/pact_broker/versions/branch_version_repository.rb, line 6
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

Private Instance Methods

create_branch(pacticipant, branch_name) click to toggle source
# File lib/pact_broker/versions/branch_version_repository.rb, line 29
def create_branch(pacticipant, branch_name)
  PactBroker::Versions::Branch.new(pacticipant: pacticipant, name: branch_name).insert_ignore
end
find_branch(pacticipant, branch_name) click to toggle source
# File lib/pact_broker/versions/branch_version_repository.rb, line 25
def find_branch(pacticipant, branch_name)
  PactBroker::Versions::Branch.where(pacticipant: pacticipant, name: branch_name).single_record
end
find_or_create_branch(pacticipant, branch_name) click to toggle source
# File lib/pact_broker/versions/branch_version_repository.rb, line 21
def find_or_create_branch(pacticipant, branch_name)
  find_branch(pacticipant, branch_name) || create_branch(pacticipant, branch_name)
end