Commit 1a8f43ff authored by Gabriel Gizotti's avatar Gabriel Gizotti

introduce MergeRequest#issues_mentioned_but_not_closing

parent e52e3ab5
...@@ -568,6 +568,22 @@ class MergeRequest < ActiveRecord::Base ...@@ -568,6 +568,22 @@ class MergeRequest < ActiveRecord::Base
end end
end end
def issues_mentioned_but_not_closing(current_user = self.author)
issues = []
if target_branch == project.default_branch
messages = [description]
messages.concat(commits.map(&:safe_message)) if merge_request_diff
ext = Gitlab::ReferenceExtractor.new(project, current_user)
ext.analyze(messages.join("\n"))
issues = ext.issues
end
issues - closes_issues
end
def target_project_path def target_project_path
if target_project if target_project
target_project.path_with_namespace target_project.path_with_namespace
......
...@@ -252,7 +252,7 @@ describe MergeRequest, models: true do ...@@ -252,7 +252,7 @@ describe MergeRequest, models: true do
end end
end end
describe 'detection of issues to be closed' do describe 'detection of issues' do
let(:issue0) { create :issue, project: subject.project } let(:issue0) { create :issue, project: subject.project }
let(:issue1) { create :issue, project: subject.project } let(:issue1) { create :issue, project: subject.project }
...@@ -265,6 +265,7 @@ describe MergeRequest, models: true do ...@@ -265,6 +265,7 @@ describe MergeRequest, models: true do
allow(subject).to receive(:commits).and_return([commit0, commit1, commit2]) allow(subject).to receive(:commits).and_return([commit0, commit1, commit2])
end end
describe 'detection of issues to be closed' do
it 'accesses the set of issues that will be closed on acceptance' do it 'accesses the set of issues that will be closed on acceptance' do
allow(subject.project).to receive(:default_branch). allow(subject.project).to receive(:default_branch).
and_return(subject.target_branch) and_return(subject.target_branch)
...@@ -283,7 +284,9 @@ describe MergeRequest, models: true do ...@@ -283,7 +284,9 @@ describe MergeRequest, models: true do
it 'detects issues mentioned in the description' do it 'detects issues mentioned in the description' do
issue2 = create(:issue, project: subject.project) issue2 = create(:issue, project: subject.project)
subject.description = "Closes #{issue2.to_reference}" subject.description = "Closes #{issue2.to_reference}"
allow(subject.project).to receive(:default_branch). allow(subject.project).to receive(:default_branch).
and_return(subject.target_branch) and_return(subject.target_branch)
...@@ -291,6 +294,18 @@ describe MergeRequest, models: true do ...@@ -291,6 +294,18 @@ describe MergeRequest, models: true do
end end
end end
it 'detects issues mentioned but not closed' do
mentioned_issue = create(:issue, project: subject.project)
subject.description = "Is related to #{mentioned_issue.to_reference}"
allow(subject.project).to receive(:default_branch).
and_return(subject.target_branch)
expect(subject.issues_mentioned_but_not_closing).to match_array([mentioned_issue])
end
end
describe "#work_in_progress?" do describe "#work_in_progress?" do
['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix| ['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix|
it "detects the '#{wip_prefix}' prefix" do it "detects the '#{wip_prefix}' prefix" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment