diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-04-02 16:38:24 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-04-02 16:38:24 +0400 |
commit | cc773654883d34c70462eeeeb280453473c35e21 (patch) | |
tree | a246f2a4246bf34407c3ab73a353b30c319abccc /app/services | |
parent | 0d41f6f0a3ab23cee63e349eda5fb79240734dd4 (diff) |
Create services for issue close and reopen
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/git_push_service.rb | 7 | ||||
-rw-r--r-- | app/services/issues/base_service.rb | 5 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 20 | ||||
-rw-r--r-- | app/services/issues/reopen_service.rb | 19 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 2 |
5 files changed, 43 insertions, 10 deletions
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index fcc03c3e4b8..351b446457d 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -86,10 +86,9 @@ class GitPushService author = commit_user(commit) if !issues_to_close.empty? && is_default_branch - Thread.current[:current_user] = author - Thread.current[:current_commit] = commit - - issues_to_close.each { |i| i.close && i.save } + issues_to_close.each do |issue| + Issues::CloseService.new(project, author, {}).execute(issue, commit) + end end # Create cross-reference notes for any other references. Omit any issues that were referenced in an diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index e04c1c6fb7a..2e1e1f7e0f0 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -3,11 +3,6 @@ module Issues private - # Create issue note with service comment like 'Status changed to closed' - def create_note(issue) - Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit) - end - def create_assignee_note(issue) Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee) end diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb new file mode 100644 index 00000000000..780bc8e4130 --- /dev/null +++ b/app/services/issues/close_service.rb @@ -0,0 +1,20 @@ +module Issues + class CloseService < BaseService + def execute(issue, commit = nil) + if issue.close + notification_service.close_issue(issue, current_user) + event_service.close_issue(issue, current_user) + create_note(issue, commit) + execute_hooks(issue) + end + + issue + end + + private + + def create_note(issue, current_commit) + Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit) + end + end +end diff --git a/app/services/issues/reopen_service.rb b/app/services/issues/reopen_service.rb new file mode 100644 index 00000000000..743a5d6c4a8 --- /dev/null +++ b/app/services/issues/reopen_service.rb @@ -0,0 +1,19 @@ +module Issues + class ReopenService < BaseService + def execute(issue) + if issue.reopen + event_service.reopen_issue(issue, current_user) + create_note(issue, commit) + execute_hooks(issue) + end + + issue + end + + private + + def create_note(issue) + Note.create_status_change_note(issue, issue.project, current_user, issue.state, nil) + end + end +end diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index 4db9dee11d3..4d8d71b4c9f 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -5,7 +5,7 @@ module Issues issue.reset_events_cache if issue.is_being_reassigned? - notification.reassigned_issue(issue, current_user) + notification_service.reassigned_issue(issue, current_user) create_assignee_note(issue) end |