Class: PactBroker::Webhooks::Repository

Inherits:
Object
  • Object
show all
Includes:
Repositories
Defined in:
lib/pact_broker/webhooks/repository.rb

Instance Method Summary collapse

Methods included from Repositories

#pact_repository, #pacticipant_repository, #tag_repository, #verification_repository, #version_repository, #webhook_repository

Instance Method Details

#create(uuid, webhook, consumer, provider) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/pact_broker/webhooks/repository.rb', line 15

def create uuid, webhook, consumer, provider
  db_webhook = Webhook.from_domain webhook, consumer, provider
  db_webhook.uuid = uuid
  db_webhook.save
  webhook.request.headers.each_pair do | name, value |
    db_webhook.add_header PactBroker::Webhooks::WebhookHeader.from_domain(name, value, db_webhook.id)
  end
  find_by_uuid db_webhook.uuid
end

#create_execution(webhook, webhook_execution_result) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/pact_broker/webhooks/repository.rb', line 46

def create_execution webhook, webhook_execution_result
  db_webhook = Webhook.where(uuid: webhook.uuid).single_record
  execution = Execution.create(
    webhook: db_webhook,
    consumer: db_webhook.consumer,
    provider: db_webhook.provider,
    success: webhook_execution_result.success?,
    logs: webhook_execution_result.logs)
end

#delete_by_pacticipant(pacticipant) ⇒ Object



33
34
35
36
# File 'lib/pact_broker/webhooks/repository.rb', line 33

def delete_by_pacticipant pacticipant
  Webhook.where(consumer_id: pacticipant.id).destroy
  Webhook.where(provider_id: pacticipant.id).destroy
end

#delete_by_uuid(uuid) ⇒ Object



29
30
31
# File 'lib/pact_broker/webhooks/repository.rb', line 29

def delete_by_uuid uuid
  Webhook.where(uuid: uuid).destroy
end

#delete_executions_by_pacticipant(pacticipant) ⇒ Object



56
57
58
59
# File 'lib/pact_broker/webhooks/repository.rb', line 56

def delete_executions_by_pacticipant pacticipant
  Execution.where(consumer: pacticipant).delete
  Execution.where(provider: pacticipant).delete
end

#find_allObject



38
39
40
# File 'lib/pact_broker/webhooks/repository.rb', line 38

def find_all
  Webhook.all.collect(&:to_domain)
end

#find_by_consumer_and_provider(consumer, provider) ⇒ Object



42
43
44
# File 'lib/pact_broker/webhooks/repository.rb', line 42

def find_by_consumer_and_provider consumer, provider
  Webhook.where(consumer_id: consumer.id, provider_id: provider.id).collect(&:to_domain)
end

#find_by_uuid(uuid) ⇒ Object



25
26
27
# File 'lib/pact_broker/webhooks/repository.rb', line 25

def find_by_uuid uuid
  Webhook.where(uuid: uuid).limit(1).collect(&:to_domain)[0]
end


61
62
63
# File 'lib/pact_broker/webhooks/repository.rb', line 61

def unlink_executions_by_webhook_uuid uuid
  Execution.where(webhook: Webhook.where(uuid: uuid)).update(webhook_id: nil)
end