Commit 3f1ece26909f90e538a50cd724b64da28f0b7308
1 parent
5fdcaadf
Exists in
spb-stable
and in
2 other branches
Detect closing issues in Merge Request description
Showing
5 changed files
with
29 additions
and
14 deletions
Show diff stats
CHANGELOG
... | ... | @@ -35,6 +35,7 @@ v 7.0.0 |
35 | 35 | - Be more selective when killing stray Sidekiqs |
36 | 36 | - Check LDAP user filter during sign-in |
37 | 37 | - Remove wall feature (no data loss - you can take it from database) |
38 | + - Detect issues closed by Merge Request description | |
38 | 39 | |
39 | 40 | v 6.9.2 |
40 | 41 | - Revert the commit that broke the LDAP user filter | ... | ... |
app/models/commit.rb
... | ... | @@ -111,22 +111,10 @@ class Commit |
111 | 111 | description.present? |
112 | 112 | end |
113 | 113 | |
114 | - # Regular expression that identifies commit message clauses that trigger issue closing. | |
115 | - def issue_closing_regex | |
116 | - @issue_closing_regex ||= Regexp.new(Gitlab.config.gitlab.issue_closing_pattern) | |
117 | - end | |
118 | - | |
119 | 114 | # Discover issues should be closed when this commit is pushed to a project's |
120 | 115 | # default branch. |
121 | 116 | def closes_issues project |
122 | - md = issue_closing_regex.match(safe_message) | |
123 | - if md | |
124 | - extractor = Gitlab::ReferenceExtractor.new | |
125 | - extractor.analyze(md[0]) | |
126 | - extractor.issues_for(project) | |
127 | - else | |
128 | - [] | |
129 | - end | |
117 | + Gitlab::ClosingIssueExtractor.closed_by_message_in_project(safe_message, project) | |
130 | 118 | end |
131 | 119 | |
132 | 120 | # Mentionable override. | ... | ... |
app/models/merge_request.rb
... | ... | @@ -220,7 +220,9 @@ class MergeRequest < ActiveRecord::Base |
220 | 220 | # Return the set of issues that will be closed if this merge request is accepted. |
221 | 221 | def closes_issues |
222 | 222 | if target_branch == project.default_branch |
223 | - commits.map { |c| c.closes_issues(project) }.flatten.uniq.sort_by(&:id) | |
223 | + issues = commits.flat_map { |c| c.closes_issues(project) } | |
224 | + issues += Gitlab::ClosingIssueExtractor.closed_by_message_in_project(description, project) | |
225 | + issues.uniq.sort_by(&:id) | |
224 | 226 | else |
225 | 227 | [] |
226 | 228 | end | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +module Gitlab | |
2 | + module ClosingIssueExtractor | |
3 | + ISSUE_CLOSING_REGEX = Regexp.new(Gitlab.config.gitlab.issue_closing_pattern) | |
4 | + | |
5 | + def self.closed_by_message_in_project(message, project) | |
6 | + md = ISSUE_CLOSING_REGEX.match(message) | |
7 | + if md | |
8 | + extractor = Gitlab::ReferenceExtractor.new | |
9 | + extractor.analyze(md[0]) | |
10 | + extractor.issues_for(project) | |
11 | + else | |
12 | + [] | |
13 | + end | |
14 | + end | |
15 | + end | |
16 | +end | ... | ... |
spec/models/merge_request_spec.rb
... | ... | @@ -105,6 +105,14 @@ describe MergeRequest do |
105 | 105 | |
106 | 106 | subject.closes_issues.should be_empty |
107 | 107 | end |
108 | + | |
109 | + it 'detects issues mentioned in the description' do | |
110 | + issue2 = create(:issue, project: subject.project) | |
111 | + subject.description = "Closes ##{issue2.iid}" | |
112 | + subject.project.stub(default_branch: subject.target_branch) | |
113 | + | |
114 | + subject.closes_issues.should include(issue2) | |
115 | + end | |
108 | 116 | end |
109 | 117 | |
110 | 118 | it_behaves_like 'an editable mentionable' do | ... | ... |