Merge remote-tracking branch 'origin/issue_closing_widget'
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: CHANGELOG
This commit is contained in:
commit
49506fc71a
5 changed files with 29 additions and 14 deletions
|
@ -36,6 +36,7 @@ v 7.0.0
|
|||
- Check LDAP user filter during sign-in
|
||||
- Remove wall feature (no data loss - you can take it from database)
|
||||
- Dont expose user emails via API unless you are admin
|
||||
- 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
|
||||
|
|
16
lib/gitlab/closing_issue_extractor.rb
Normal file
16
lib/gitlab/closing_issue_extractor.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue