summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-14 12:40:42 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-14 12:40:42 +0300
commit49506fc71a03e39a1a316e6740423a44030526ed (patch)
treeb264b83f69fb833a6d950107b11c0c89cd9effb3
parent55d4e2647d10a237705a1e2a65e24f33f654c75b (diff)
parent3f1ece26909f90e538a50cd724b64da28f0b7308 (diff)
downloadgitlab-ce-49506fc71a03e39a1a316e6740423a44030526ed.tar.gz
Merge remote-tracking branch 'origin/issue_closing_widget'
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: CHANGELOG
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/commit.rb14
-rw-r--r--app/models/merge_request.rb4
-rw-r--r--lib/gitlab/closing_issue_extractor.rb16
-rw-r--r--spec/models/merge_request_spec.rb8
5 files changed, 29 insertions, 14 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c353c3b770c..8fa1fb000ad 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 81875e1be2d..82876e10446 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -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.
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index a501870115f..bfea209bf6d 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -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
diff --git a/lib/gitlab/closing_issue_extractor.rb b/lib/gitlab/closing_issue_extractor.rb
new file mode 100644
index 00000000000..90f1370c209
--- /dev/null
+++ b/lib/gitlab/closing_issue_extractor.rb
@@ -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
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 81a48699cd8..1148df87ab7 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -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