diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-10-05 17:40:57 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-10-05 17:40:57 +0000 |
commit | 58a256ad0bfa10211479b2685ed2d5e19948e059 (patch) | |
tree | 7078c2506e50829e1c85d43bc71deae907c29b57 /app/services | |
parent | b407061a281607e0c4bf22d2b7e94a068768ccac (diff) | |
parent | 0ae48e068794a732f728de76ffbf3f95e702ba9a (diff) | |
download | gitlab-ce-58a256ad0bfa10211479b2685ed2d5e19948e059.tar.gz |
Merge branch 'issue_43097' into 'master'
Move related branches to service
Closes #43097
See merge request gitlab-org/gitlab-ce!22094
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issues/related_branches_service.rb | 26 |
1 files changed, 26 insertions, 0 deletions
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 |