2013-04-25 10:15:33 -04:00
|
|
|
class MergeRequestObserver < ActivityObserver
|
|
|
|
observe :merge_request
|
|
|
|
|
2012-10-09 18:25:29 -04:00
|
|
|
def after_create(merge_request)
|
2013-07-16 17:14:03 -04:00
|
|
|
if merge_request.author_id
|
2013-04-25 10:15:33 -04:00
|
|
|
create_event(merge_request, Event.determine_action(merge_request))
|
|
|
|
end
|
|
|
|
|
2013-03-26 11:16:06 -04:00
|
|
|
notification.new_merge_request(merge_request, current_user)
|
2013-05-30 19:16:49 -04:00
|
|
|
merge_request.create_cross_references!(merge_request.project, current_user)
|
2013-12-03 04:34:06 -05:00
|
|
|
execute_hooks(merge_request)
|
2012-10-09 18:25:29 -04:00
|
|
|
end
|
|
|
|
|
2013-02-18 03:40:56 -05:00
|
|
|
def after_close(merge_request, transition)
|
2013-04-25 10:15:33 -04:00
|
|
|
create_event(merge_request, Event::CLOSED)
|
2013-03-28 05:59:06 -04:00
|
|
|
notification.close_mr(merge_request, current_user)
|
2013-12-03 04:34:06 -05:00
|
|
|
create_note(merge_request)
|
|
|
|
execute_hooks(merge_request)
|
2013-03-28 05:59:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_merge(merge_request, transition)
|
2013-03-28 06:14:53 -04:00
|
|
|
notification.merge_mr(merge_request)
|
2013-04-25 10:15:33 -04:00
|
|
|
# Since MR can be merged via sidekiq
|
|
|
|
# to prevent event duplication do this check
|
|
|
|
return true if merge_request.merge_event
|
|
|
|
|
|
|
|
Event.create(
|
2013-07-16 17:14:03 -04:00
|
|
|
project: merge_request.target_project,
|
|
|
|
target_id: merge_request.id,
|
|
|
|
target_type: merge_request.class.name,
|
|
|
|
action: Event::MERGED,
|
|
|
|
author_id: merge_request.author_id_of_changes
|
2013-04-25 10:15:33 -04:00
|
|
|
)
|
2013-12-03 04:34:06 -05:00
|
|
|
|
|
|
|
execute_hooks(merge_request)
|
2013-02-18 03:40:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_reopen(merge_request, transition)
|
2013-04-25 10:15:33 -04:00
|
|
|
create_event(merge_request, Event::REOPENED)
|
2013-12-03 04:34:06 -05:00
|
|
|
create_note(merge_request)
|
2013-02-18 03:40:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_update(merge_request)
|
2013-04-01 05:25:31 -04:00
|
|
|
notification.reassigned_merge_request(merge_request, current_user) if merge_request.is_being_reassigned?
|
2013-05-30 19:16:49 -04:00
|
|
|
|
|
|
|
merge_request.notice_added_references(merge_request.project, current_user)
|
2012-10-09 18:25:29 -04:00
|
|
|
end
|
2013-04-25 10:15:33 -04:00
|
|
|
|
|
|
|
def create_event(record, status)
|
|
|
|
Event.create(
|
2013-07-16 17:14:03 -04:00
|
|
|
project: record.target_project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: status,
|
2013-08-14 09:02:21 -04:00
|
|
|
author_id: current_user.id
|
2013-04-25 10:15:33 -04:00
|
|
|
)
|
|
|
|
end
|
2013-12-03 04:34:06 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Create merge request note with service comment like 'Status changed to closed'
|
|
|
|
def create_note(merge_request)
|
|
|
|
Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute_hooks(merge_request)
|
2013-12-03 05:08:00 -05:00
|
|
|
if merge_request.project
|
|
|
|
merge_request.project.execute_hooks(merge_request.to_hook_data, :merge_request_hooks)
|
|
|
|
end
|
2013-12-03 04:34:06 -05:00
|
|
|
end
|
2012-10-09 18:25:29 -04:00
|
|
|
end
|