2012-02-28 09:01:14 -05:00
|
|
|
class ActivityObserver < ActiveRecord::Observer
|
2012-12-14 12:33:33 -05:00
|
|
|
observe :issue, :merge_request, :note, :milestone
|
2012-02-28 09:01:14 -05:00
|
|
|
|
|
|
|
def after_create(record)
|
2012-12-14 15:05:10 -05:00
|
|
|
event_author_id = record.author_id
|
2012-12-14 14:39:55 -05:00
|
|
|
|
2013-03-19 08:50:26 -04:00
|
|
|
if record.kind_of?(Note)
|
|
|
|
# Skip system status notes like 'status changed to close'
|
|
|
|
return true if record.note.include?("_Status changed to ")
|
|
|
|
|
|
|
|
# Skip wall notes to prevent spaming of dashboard
|
|
|
|
return true if record.noteable_type.blank?
|
2012-12-14 14:39:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if event_author_id
|
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event.determine_action(record),
|
|
|
|
author_id: event_author_id
|
|
|
|
)
|
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|
2012-03-07 03:13:43 -05:00
|
|
|
|
2013-02-18 07:49:17 -05:00
|
|
|
def after_close(record, transition)
|
2013-02-25 14:26:15 -05:00
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event::CLOSED,
|
|
|
|
author_id: record.author_id_of_changes
|
|
|
|
)
|
2013-02-18 07:49:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_reopen(record, transition)
|
2013-02-25 14:26:15 -05:00
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event::REOPENED,
|
|
|
|
author_id: record.author_id_of_changes
|
|
|
|
)
|
2012-03-07 03:13:43 -05:00
|
|
|
end
|
2013-02-27 10:48:51 -05:00
|
|
|
|
|
|
|
def after_merge(record, transition)
|
|
|
|
# Since MR can be merged via sidekiq
|
|
|
|
# to prevent event duplication do this check
|
|
|
|
return true if record.merge_event
|
|
|
|
|
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event::MERGED,
|
|
|
|
author_id: record.author_id_of_changes
|
|
|
|
)
|
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|