Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/shipit/webhooks/handlers/status_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StatusHandler < Handler
end

def process
Commit.where(sha: params.sha).each do |commit|
Commit.where(sha: params.sha, stack_id: stacks.select(:id)).each do |commit|
commit.create_status_from_github!(params)
end
end
Expand Down
22 changes: 20 additions & 2 deletions test/controllers/webhooks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WebhooksControllerTest < ActionController::TestCase

commit = shipit_commits(:first)

body = JSON.parse(payload(:status_master)).merge(repository_params).to_json
body = JSON.parse(payload(:status_master)).merge(repository_params.deep_stringify_keys).to_json
assert_difference 'commit.statuses.count', 1 do
post :create, body:, as: :json
end
Expand All @@ -58,6 +58,24 @@ class WebhooksControllerTest < ActionController::TestCase
assert_equal status_payload['created_at'], status.created_at.iso8601
end

test ":status only updates matching commits in the payload repository" do
request.headers['X-Github-Event'] = 'status'

commit = shipit_commits(:first)
canary_commit = shipit_commits(:canaries_first)
other_commit = shipit_commits(:undeployed_stack_first)
other_commit.update!(sha: commit.sha)

body = JSON.parse(payload(:status_master)).merge(repository_params.deep_stringify_keys).to_json

assert_difference [-> { commit.statuses.count }, -> { canary_commit.statuses.count }], 1 do
assert_no_difference -> { other_commit.statuses.count } do
post :create, body:, as: :json
assert_response :ok
end
end
end

test ":state with a unexisting commit respond with 200 OK" do
request.headers['X-Github-Event'] = 'status'
params = { 'sha' => 'notarealcommit', 'state' => 'pending', 'branches' => [{ 'name' => 'master' }] }.merge(repository_params).to_json
Expand Down Expand Up @@ -214,7 +232,7 @@ def team_params
end

def repository_params
{ repository: { owner: { login: 'shopify' } } }
{ repository: { full_name: @stack.github_repo_name, owner: { login: 'shopify' } } }
end

def george
Expand Down
Loading