Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
3f1ece26
Commit
3f1ece26
authored
Jun 13, 2014
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect closing issues in Merge Request description
parent
5fdcaadf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
14 deletions
+29
-14
CHANGELOG
CHANGELOG
+1
-0
app/models/commit.rb
app/models/commit.rb
+1
-13
app/models/merge_request.rb
app/models/merge_request.rb
+3
-1
lib/gitlab/closing_issue_extractor.rb
lib/gitlab/closing_issue_extractor.rb
+16
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+8
-0
No files found.
CHANGELOG
View file @
3f1ece26
...
@@ -35,6 +35,7 @@ v 7.0.0
...
@@ -35,6 +35,7 @@ v 7.0.0
- Be more selective when killing stray Sidekiqs
- Be more selective when killing stray Sidekiqs
- Check LDAP user filter during sign-in
- Check LDAP user filter during sign-in
- Remove wall feature (no data loss - you can take it from database)
- Remove wall feature (no data loss - you can take it from database)
- Detect issues closed by Merge Request description
v 6.9.2
v 6.9.2
- Revert the commit that broke the LDAP user filter
- Revert the commit that broke the LDAP user filter
...
...
app/models/commit.rb
View file @
3f1ece26
...
@@ -111,22 +111,10 @@ class Commit
...
@@ -111,22 +111,10 @@ class Commit
description
.
present?
description
.
present?
end
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
# Discover issues should be closed when this commit is pushed to a project's
# default branch.
# default branch.
def
closes_issues
project
def
closes_issues
project
md
=
issue_closing_regex
.
match
(
safe_message
)
Gitlab
::
ClosingIssueExtractor
.
closed_by_message_in_project
(
safe_message
,
project
)
if
md
extractor
=
Gitlab
::
ReferenceExtractor
.
new
extractor
.
analyze
(
md
[
0
])
extractor
.
issues_for
(
project
)
else
[]
end
end
end
# Mentionable override.
# Mentionable override.
...
...
app/models/merge_request.rb
View file @
3f1ece26
...
@@ -220,7 +220,9 @@ class MergeRequest < ActiveRecord::Base
...
@@ -220,7 +220,9 @@ class MergeRequest < ActiveRecord::Base
# Return the set of issues that will be closed if this merge request is accepted.
# Return the set of issues that will be closed if this merge request is accepted.
def
closes_issues
def
closes_issues
if
target_branch
==
project
.
default_branch
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
else
[]
[]
end
end
...
...
lib/gitlab/closing_issue_extractor.rb
0 → 100644
View file @
3f1ece26
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
spec/models/merge_request_spec.rb
View file @
3f1ece26
...
@@ -105,6 +105,14 @@ describe MergeRequest do
...
@@ -105,6 +105,14 @@ describe MergeRequest do
subject
.
closes_issues
.
should
be_empty
subject
.
closes_issues
.
should
be_empty
end
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
end
it_behaves_like
'an editable mentionable'
do
it_behaves_like
'an editable mentionable'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment