Commit 3f1ece26 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Detect closing issues in Merge Request description

parent 5fdcaadf
......@@ -35,6 +35,7 @@ v 7.0.0
- Be more selective when killing stray Sidekiqs
- Check LDAP user filter during sign-in
- Remove wall feature (no data loss - you can take it from database)
- Detect issues closed by Merge Request description
v 6.9.2
- Revert the commit that broke the LDAP user filter
......
......@@ -111,22 +111,10 @@ class Commit
description.present?
end
# Regular expression that identifies commit message clauses that trigger issue closing.
def issue_closing_regex
@issue_closing_regex ||= Regexp.new(Gitlab.config.gitlab.issue_closing_pattern)
end
# Discover issues should be closed when this commit is pushed to a project's
# default branch.
def closes_issues project
md = issue_closing_regex.match(safe_message)
if md
extractor = Gitlab::ReferenceExtractor.new
extractor.analyze(md[0])
extractor.issues_for(project)
else
[]
end
Gitlab::ClosingIssueExtractor.closed_by_message_in_project(safe_message, project)
end
# Mentionable override.
......
......@@ -220,7 +220,9 @@ class MergeRequest < ActiveRecord::Base
# Return the set of issues that will be closed if this merge request is accepted.
def closes_issues
if target_branch == project.default_branch
commits.map { |c| c.closes_issues(project) }.flatten.uniq.sort_by(&:id)
issues = commits.flat_map { |c| c.closes_issues(project) }
issues += Gitlab::ClosingIssueExtractor.closed_by_message_in_project(description, project)
issues.uniq.sort_by(&:id)
else
[]
end
......
module Gitlab
module ClosingIssueExtractor
ISSUE_CLOSING_REGEX = Regexp.new(Gitlab.config.gitlab.issue_closing_pattern)
def self.closed_by_message_in_project(message, project)
md = ISSUE_CLOSING_REGEX.match(message)
if md
extractor = Gitlab::ReferenceExtractor.new
extractor.analyze(md[0])
extractor.issues_for(project)
else
[]
end
end
end
end
......@@ -105,6 +105,14 @@ describe MergeRequest do
subject.closes_issues.should be_empty
end
it 'detects issues mentioned in the description' do
issue2 = create(:issue, project: subject.project)
subject.description = "Closes ##{issue2.iid}"
subject.project.stub(default_branch: subject.target_branch)
subject.closes_issues.should include(issue2)
end
end
it_behaves_like 'an editable mentionable' 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