Skip to content

Commit

Permalink
feat(webhook status): add endpoint for triggered webhook execution logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 21, 2017
1 parent dc283ad commit ad81d20
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions db/migrations/38_create_triggered_webhooks_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
String :status, null: false
DateTime :created_at, null: false
DateTime :updated_at, null: false
add_index [:webhook_id, :trigger_uuid], unique: true, name: 'uq_triggered_webhook_wi'
add_index [:pact_publication_id, :webhook_id, :trigger_uuid], unique: true, name: 'uq_triggered_webhook_ppi_wi'
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/pact_broker/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module PactBroker
add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name, 'status' ], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks"}

add ['webhooks', :uuid ], Api::Resources::Webhook, {resource_name: "webhook"}
add ['webhooks', :uuid, 'trigger', :trigger_uuid, 'logs' ], Api::Resources::TriggeredWebhookLogs, {resource_name: "triggered_webhook_logs"}
add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution, {resource_name: "execute_webhook"}
add ['webhooks'], Api::Resources::Webhooks, {resource_name: "webhooks"}

Expand Down
36 changes: 36 additions & 0 deletions lib/pact_broker/api/resources/triggered_webhook_logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'pact_broker/api/resources/base_resource'
require 'pact_broker/webhooks/triggered_webhook'

module PactBroker
module Api
module Resources

class TriggeredWebhookLogs < BaseResource

def content_types_provided
[["text/plain", :to_text]]
end

def allowed_methods
["GET"]
end

def resource_exists?
triggered_webhook
end

def to_text
# Too simple to bother putting into a service
triggered_webhook.webhook_executions.collect(&:logs).join("\n")
end

def triggered_webhook
@triggered_webhook ||= begin
criteria = {webhook_uuid: identifier_from_path[:uuid], trigger_uuid: identifier_from_path[:trigger_uuid]}
PactBroker::Webhooks::TriggeredWebhook.where(criteria).single_record
end
end
end
end
end
end
28 changes: 28 additions & 0 deletions spec/lib/pact_broker/api/resources/triggered_webhook_logs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'pact_broker/api/resources/triggered_webhook_logs'

module PactBroker
module Api
module Resources
describe TriggeredWebhookLogs do

let(:td) { TestDataBuilder.new }

before do
td.create_pact_with_hierarchy
.create_webhook(uuid: "5432")
.create_triggered_webhook(trigger_uuid: "1234")
.create_webhook_execution(logs: "foo")
.create_webhook_execution(logs: "bar")
end

let(:path) { "/webhooks/5432/trigger/1234/logs" }

subject { get path; last_response }

it "returns the concatenated webhook execution logs" do
expect(subject.body).to eq "foo\nbar"
end
end
end
end
end

0 comments on commit ad81d20

Please sign in to comment.