diff --git a/app/models/shipit/webhooks/handlers/status_handler.rb b/app/models/shipit/webhooks/handlers/status_handler.rb index b19e9af1f..a0c74205d 100644 --- a/app/models/shipit/webhooks/handlers/status_handler.rb +++ b/app/models/shipit/webhooks/handlers/status_handler.rb @@ -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 diff --git a/test/controllers/webhooks_controller_test.rb b/test/controllers/webhooks_controller_test.rb index 805447d1b..28cdb7ad4 100644 --- a/test/controllers/webhooks_controller_test.rb +++ b/test/controllers/webhooks_controller_test.rb @@ -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 @@ -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 @@ -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