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

Andrew8xx8's avatar
Andrew8xx8 committed
9
  def after_close(issue, transition)
10
    notification.close_issue(issue, current_user)
11
    event_service.close_issue(issue, current_user)
Andrew8xx8's avatar
Andrew8xx8 committed
12
    create_note(issue)
13
    execute_hooks(issue)
Andrew8xx8's avatar
Andrew8xx8 committed
14 15 16
  end

  def after_reopen(issue, transition)
17
    event_service.reopen_issue(issue, current_user)
Andrew8xx8's avatar
Andrew8xx8 committed
18
    create_note(issue)
19
    execute_hooks(issue)
Andrew8xx8's avatar
Andrew8xx8 committed
20 21 22
  end

  def after_update(issue)
23 24
    if issue.is_being_reassigned?
      notification.reassigned_issue(issue, current_user)
25
      create_assignee_note(issue)
26
    end
27 28

    issue.notice_added_references(issue.project, current_user)
29
    execute_hooks(issue)
30 31
  end

32 33
  protected

34
  # Create issue note with service comment like 'Status changed to closed'
Andrew8xx8's avatar
Andrew8xx8 committed
35
  def create_note(issue)
36
    Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit)
Andrew8xx8's avatar
Andrew8xx8 committed
37
  end
38

39 40 41 42
  def create_assignee_note(issue)
    Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee)
  end

43 44 45
  def execute_hooks(issue)
    issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
  end
46
end