summaryrefslogtreecommitdiff
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-08-16 11:07:43 +0100
committerSean McGivern <sean@gitlab.com>2018-08-21 12:40:44 +0100
commitc73da6c1e73f04ece18b5fca5ccd67bf918682f8 (patch)
tree40343fc8215ec0496d1aec604c394bbaac511510 /app/models/issue.rb
parent6ac7162395a2651b992cf8c25436e20fde92252d (diff)
downloadgitlab-ce-c73da6c1e73f04ece18b5fca5ccd67bf918682f8.tar.gz
Move Issue#{referenced,closed_by}_merge_requests to service
These methods don't really need to be on the Issue model. Issue#related_branches can also be moved to a service, but we can do that in a separate commit. This commit does not change any behaviour; it just moves code around, renames the service, and refactors the specs.
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb47
1 files changed, 5 insertions, 42 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 94cf12f3c2b..d0cd7461daa 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -170,27 +170,6 @@ class Issue < ActiveRecord::Base
"#{project.to_reference(from, full: full)}#{reference}"
end
- def referenced_merge_requests(current_user = nil)
- ext = all_references(current_user)
-
- notes_with_associations.each do |object|
- object.all_references(current_user, extractor: ext)
- end
-
- merge_requests = ext.merge_requests.sort_by(&:iid)
-
- cross_project_filter = -> (merge_requests) do
- merge_requests.select { |mr| mr.target_project == project }
- end
-
- Ability.merge_requests_readable_by_user(
- merge_requests, current_user,
- filters: {
- read_cross_project: cross_project_filter
- }
- )
- end
-
# All branches containing the current issue's ID, except for
# those with a merge request open referencing the current issue.
def related_branches(current_user)
@@ -198,7 +177,11 @@ class Issue < ActiveRecord::Base
branch =~ /\A#{iid}-(?!\d+-stable)/i
end
- branches_with_merge_request = self.referenced_merge_requests(current_user).map(&:source_branch)
+ branches_with_merge_request =
+ Issues::ReferencedMergeRequestsService
+ .new(project, current_user)
+ .referenced_merge_requests(self)
+ .map(&:source_branch)
branches_with_iid - branches_with_merge_request
end
@@ -225,26 +208,6 @@ class Issue < ActiveRecord::Base
project
end
- # From all notes on this issue, we'll select the system notes about linked
- # merge requests. Of those, the MRs closing `self` are returned.
- def closed_by_merge_requests(current_user = nil)
- return [] unless open?
-
- ext = all_references(current_user)
-
- notes.system.each do |note|
- note.all_references(current_user, extractor: ext)
- end
-
- merge_requests = ext.merge_requests.select(&:open?)
- if merge_requests.any?
- ids = MergeRequestsClosingIssues.where(merge_request_id: merge_requests.map(&:id), issue_id: id).pluck(:merge_request_id)
- merge_requests.select { |mr| mr.id.in?(ids) }
- else
- []
- end
- end
-
def moved?
!moved_to.nil?
end