BigW Consortium Gitlab

Commit 04ee970c by Jarka Kadlecova Committed by Douwe Maan

Don't create event in Merge Request Create Service

parent aae23494
......@@ -25,7 +25,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)
......
# 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
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170809161910) do
ActiveRecord::Schema.define(version: 20170815060945) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
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
......@@ -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
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment