BigW Consortium Gitlab

issue_observer.rb 1.12 KB
Newer Older
1
class IssueObserver < BaseObserver
2
  def after_create(issue)
3
    notification.new_issue(issue, current_user)
4
    issue.create_cross_references!(issue.project, current_user)
5
    execute_hooks(issue)
6 7
  end

Andrew8xx8 committed
8
  def after_close(issue, transition)
9
    notification.close_issue(issue, current_user)
Andrew8xx8 committed
10
    create_note(issue)
11
    execute_hooks(issue)
Andrew8xx8 committed
12 13 14 15
  end

  def after_reopen(issue, transition)
    create_note(issue)
16
    execute_hooks(issue)
Andrew8xx8 committed
17 18 19
  end

  def after_update(issue)
20 21
    if issue.is_being_reassigned?
      notification.reassigned_issue(issue, current_user)
22
      create_assignee_note(issue)
23
    end
24 25

    issue.notice_added_references(issue.project, current_user)
26
    execute_hooks(issue)
27 28
  end

29 30
  protected

31
  # Create issue note with service comment like 'Status changed to closed'
Andrew8xx8 committed
32
  def create_note(issue)
33
    Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit)
Andrew8xx8 committed
34
  end
35

36 37 38 39
  def create_assignee_note(issue)
    Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee)
  end

40 41 42
  def execute_hooks(issue)
    issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
  end
43
end