Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #959 from monstermunchkin/issues/958
Browse files Browse the repository at this point in the history
webhooks: handle delete events
  • Loading branch information
mssola authored Jul 7, 2016
2 parents bc98ce4 + 60354bb commit 70b10ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ def self.handle_push_event(event)
hydra.run
end

# Handle a delete event from the registry. All enabled webhooks of the provided
# namespace are triggered in parallel.
def self.handle_delete_event(event)
handle_push_event(event)
end

# host returns the host part of the URL. This is useful when wanting a pretty
# representation of a webhook.
def host
Expand Down
16 changes: 15 additions & 1 deletion spec/models/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
it { should define_enum_for(:content_type) }
it { should allow_value(*content_types).for(:content_type) }

describe "push event" do
describe "push and delete events" do
let!(:registry) { create(:registry) }
let!(:owner) { create(:user) }
let!(:team) { create(:team, owners: [owner]) }
Expand Down Expand Up @@ -69,24 +69,38 @@
delivery = WebhookDelivery.find_by(webhook: webhook_auth)
expect(delivery.status).to eq 200
expect(JSON.parse(delivery.request_body)).to eq event

Webhook.handle_delete_event(event)
delivery = WebhookDelivery.find_by(webhook: webhook_auth)
expect(delivery.status).to eq 200
expect(JSON.parse(delivery.request_body)).to eq event
end

it "should work when providing no user credentials" do
Webhook.handle_push_event(event)
delivery = WebhookDelivery.find_by(webhook: webhook_noauth)
expect(delivery.status).to eq 200
expect(JSON.parse(delivery.request_body)).to eq event

Webhook.handle_delete_event(event)
delivery = WebhookDelivery.find_by(webhook: webhook_noauth)
expect(delivery.status).to eq 200
expect(JSON.parse(delivery.request_body)).to eq event
end

it "should fail in the given namespace cannot be found" do
event["target"]["repository"] = "unknown_namespace/unknown_repo"
expect(Webhook.handle_push_event(event)).to be nil
expect(Webhook.handle_delete_event(event)).to be nil
end
end

it "should skip disabled webhooks" do
Webhook.handle_push_event(event)
expect(WebhookDelivery.all).to be_empty

Webhook.handle_delete_event(event)
expect(WebhookDelivery.all).to be_empty
end
end
end

0 comments on commit 70b10ca

Please sign in to comment.