diff options
author | Felipe Artur <felipefac@gmail.com> | 2018-10-03 17:45:39 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2018-10-04 15:59:14 -0300 |
commit | 0ae48e068794a732f728de76ffbf3f95e702ba9a (patch) | |
tree | e63047572f6dfc7533af377f7329dd242b7f396d /app | |
parent | 8a8ae2f57fe0db9b33f100e9a68c9eac4fd71c4d (diff) | |
download | gitlab-ce-0ae48e068794a732f728de76ffbf3f95e702ba9a.tar.gz |
Move issue related_branches to service
Moves the related_branches method from Issue model
to RelatedBranchesService
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/issues_controller.rb | 2 | ||||
-rw-r--r-- | app/models/issue.rb | 18 | ||||
-rw-r--r-- | app/services/issues/related_branches_service.rb | 26 |
3 files changed, 27 insertions, 19 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 4e859de6fde..b06a6f3bb0d 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -127,7 +127,7 @@ class Projects::IssuesController < Projects::ApplicationController end def related_branches - @related_branches = @issue.related_branches(current_user) + @related_branches = Issues::RelatedBranchesService.new(project, current_user).execute(issue) respond_to do |format| format.json do diff --git a/app/models/issue.rb b/app/models/issue.rb index d13fbcf002c..4ace5d3ab97 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -170,24 +170,6 @@ class Issue < ActiveRecord::Base "#{project.to_reference(from, full: full)}#{reference}" end - # All branches containing the current issue's ID, except for - # those with a merge request open referencing the current issue. - # rubocop: disable CodeReuse/ServiceClass - def related_branches(current_user) - branches_with_iid = project.repository.branch_names.select do |branch| - branch =~ /\A#{iid}-(?!\d+-stable)/i - end - - 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 - # rubocop: enable CodeReuse/ServiceClass - def suggested_branch_name return to_branch_name unless project.repository.branch_exists?(to_branch_name) diff --git a/app/services/issues/related_branches_service.rb b/app/services/issues/related_branches_service.rb new file mode 100644 index 00000000000..76af482b7ac --- /dev/null +++ b/app/services/issues/related_branches_service.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# This service fetches all branches containing the current issue's ID, except for +# those with a merge request open referencing the current issue. +module Issues + class RelatedBranchesService < Issues::BaseService + def execute(issue) + branches_with_iid_of(issue) - branches_with_merge_request_for(issue) + end + + private + + def branches_with_merge_request_for(issue) + Issues::ReferencedMergeRequestsService + .new(project, current_user) + .referenced_merge_requests(issue) + .map(&:source_branch) + end + + def branches_with_iid_of(issue) + project.repository.branch_names.select do |branch| + branch =~ /\A#{issue.iid}-(?!\d+-stable)/i + end + end + end +end |