diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-08-16 09:41:56 +0000 |
---|---|---|
committer | Jose Ivan Vargas <jvargas@gitlab.com> | 2017-08-16 12:28:20 -0500 |
commit | 60e54da584eb601eb9bf12e8d36237d6f1ddb462 (patch) | |
tree | 54dc1b38d5e7b9c2bf6f1ce43ce1d871cf857b39 | |
parent | 4dee8e0bf21f038c0b410fa7b34a45260de697a6 (diff) | |
download | gitlab-ce-60e54da584eb601eb9bf12e8d36237d6f1ddb462.tar.gz |
Merge branch '36465-duplicate-events' into 'master'
Don't create event in Merge Request Create Service
Closes #36465
See merge request !13566
# Conflicts:
# db/schema.rb
-rw-r--r-- | app/services/merge_requests/create_service.rb | 1 | ||||
-rw-r--r-- | db/post_migrate/20170815060945_remove_duplicate_mr_events.rb | 26 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rw-r--r-- | spec/migrations/remove_duplicate_mr_events_spec.rb | 26 | ||||
-rw-r--r-- | spec/services/merge_requests/create_service_spec.rb | 10 |
5 files changed, 63 insertions, 2 deletions
diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb index 7d539fa49e6..e09ddacd3af 100644 --- a/app/services/merge_requests/create_service.rb +++ b/app/services/merge_requests/create_service.rb @@ -24,7 +24,6 @@ module MergeRequests end def after_create(issuable) - event_service.open_mr(issuable, current_user) todo_service.new_merge_request(issuable, current_user) issuable.cache_merge_request_closes_issues!(current_user) update_merge_requests_head_pipeline(issuable) diff --git a/db/post_migrate/20170815060945_remove_duplicate_mr_events.rb b/db/post_migrate/20170815060945_remove_duplicate_mr_events.rb new file mode 100644 index 00000000000..6132b553177 --- /dev/null +++ b/db/post_migrate/20170815060945_remove_duplicate_mr_events.rb @@ -0,0 +1,26 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveDuplicateMrEvents < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + DOWNTIME = false + + class Event < ActiveRecord::Base + self.table_name = 'events' + end + + def up + base_condition = "action = 1 AND target_type = 'MergeRequest' AND created_at > '2017-08-13'" + Event.select('target_id, count(*)') + .where(base_condition) + .group('target_id').having('count(*) > 1').each do |event| + duplicates = Event.where("#{base_condition} AND target_id = #{event.target_id}").pluck(:id) + duplicates.shift + + Event.where(id: duplicates).delete_all + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 032ab6ec15d..4ac3e4f4b9e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170809134534) do +ActiveRecord::Schema.define(version: 20170815060945) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/migrations/remove_duplicate_mr_events_spec.rb b/spec/migrations/remove_duplicate_mr_events_spec.rb new file mode 100644 index 00000000000..e393374028f --- /dev/null +++ b/spec/migrations/remove_duplicate_mr_events_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20170815060945_remove_duplicate_mr_events.rb') + +describe RemoveDuplicateMrEvents, truncate: true do + let(:migration) { described_class.new } + + describe '#up' do + let(:user) { create(:user) } + let(:merge_requests) { create_list(:merge_request, 2) } + let(:issue) { create(:issue) } + let!(:events) do + [ + create(:event, :created, author: user, target: merge_requests.first), + create(:event, :created, author: user, target: merge_requests.first), + create(:event, :updated, author: user, target: merge_requests.first), + create(:event, :created, author: user, target: merge_requests.second), + create(:event, :created, author: user, target: issue), + create(:event, :created, author: user, target: issue) + ] + end + + it 'removes duplicated merge request create records' do + expect { migration.up }.to change { Event.count }.from(6).to(5) + end + end +end diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index 8fef480274d..a1f3bec42cc 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -48,6 +48,16 @@ describe MergeRequests::CreateService do expect(Todo.where(attributes).count).to be_zero end + it 'creates exactly 1 create MR event' do + attributes = { + action: Event::CREATED, + target_id: @merge_request.id, + target_type: @merge_request.class.name + } + + expect(Event.where(attributes).count).to eq(1) + end + context 'when merge request is assigned to someone' do let(:opts) do { |