Class: PactBroker::Versions::BranchRepository
Constant Summary
Constants included
from Services
Services::SERVICE_FACTORIES
Instance Method Summary
collapse
-
#build_query_for_pacticipant_branches(pacticipant, exclude:) ⇒ Object
-
#count_branches_to_delete(pacticipant, exclude:) ⇒ Object
-
#delete_branch(branch) ⇒ Object
Deletes a branch, its branch head and branch_version objects, without deleting the pacticipant version objects.
-
#delete_branches_for_pacticipant(pacticipant, exclude:) ⇒ Object
-
#find_all_branches_for_pacticipant(pacticipant, filter_options = {}, pagination_options = {}, eager_load_associations = []) ⇒ Object
-
#find_branch(pacticipant_name:, branch_name:) ⇒ PactBroker::Versions::Branch?
-
#remaining_branches_after_future_deletion(pacticipant, exclude:) ⇒ Array<PactBroker::Versions::Branch>
Returns the list of branches which will NOT be deleted (the bulk delete is executed async after the request has finished).
#scope_for, #unscoped, #with_no_scope
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
#build_query_for_pacticipant_branches(pacticipant, exclude:) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 67
def build_query_for_pacticipant_branches(pacticipant, exclude: )
exclude_dup = exclude.dup
if pacticipant.main_branch
exclude_dup << pacticipant.main_branch
end
Branch.where(pacticipant_id: pacticipant.id).exclude(name: exclude_dup)
end
|
#count_branches_to_delete(pacticipant, exclude:) ⇒ Object
45
46
47
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 45
def count_branches_to_delete(pacticipant, exclude: )
build_query_for_pacticipant_branches(pacticipant, exclude: exclude).count
end
|
#delete_branch(branch) ⇒ Object
Deletes a branch, its branch head and branch_version objects, without deleting the pacticipant version objects
38
39
40
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 38
def delete_branch(branch)
branch.delete
end
|
#delete_branches_for_pacticipant(pacticipant, exclude:) ⇒ Object
63
64
65
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 63
def delete_branches_for_pacticipant(pacticipant, exclude:)
build_query_for_pacticipant_branches(pacticipant, exclude: exclude).delete
end
|
#find_all_branches_for_pacticipant(pacticipant, filter_options = {}, pagination_options = {}, eager_load_associations = []) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 12
def find_all_branches_for_pacticipant(pacticipant, filter_options = {}, = {}, eager_load_associations = [])
query = scope_for(Branch).where(pacticipant_id: pacticipant.id).select_all_qualified
query = query.filter(:name, filter_options[:query_string]) if filter_options[:query_string]
query
.order(Sequel.desc(:created_at), Sequel.desc(:id))
.eager(*eager_load_associations)
.()
end
|
24
25
26
27
28
29
30
31
32
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 24
def find_branch(pacticipant_name:, branch_name:)
Branch
.select_all_qualified
.join(:pacticipants, { Sequel[:branches][:pacticipant_id] => Sequel[:pacticipants][:id] }) do
Sequel.name_like(Sequel[:pacticipants][:name], pacticipant_name)
end
.where(Sequel[:branches][:name] => branch_name)
.single_record
end
|
#remaining_branches_after_future_deletion(pacticipant, exclude:) ⇒ Array<PactBroker::Versions::Branch>
Returns the list of branches which will NOT be deleted (the bulk delete is executed async after the request has finished)
53
54
55
56
57
58
59
|
# File 'lib/pact_broker/versions/branch_repository.rb', line 53
def remaining_branches_after_future_deletion(pacticipant, exclude: )
exclude_dup = exclude.dup
if pacticipant.main_branch
exclude_dup << pacticipant.main_branch
end
Branch.where(pacticipant_id: pacticipant.id).where(name: exclude_dup)
end
|