BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
1a8f43ff
Commit
1a8f43ff
authored
Nov 24, 2016
by
Gabriel Gizotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introduce MergeRequest#issues_mentioned_but_not_closing
parent
e52e3ab5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
15 deletions
+46
-15
merge_request.rb
app/models/merge_request.rb
+16
-0
merge_request_spec.rb
spec/models/merge_request_spec.rb
+30
-15
No files found.
app/models/merge_request.rb
View file @
1a8f43ff
...
...
@@ -568,6 +568,22 @@ class MergeRequest < ActiveRecord::Base
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
if
target_project
target_project
.
path_with_namespace
...
...
spec/models/merge_request_spec.rb
View file @
1a8f43ff
...
...
@@ -252,7 +252,7 @@ describe MergeRequest, models: true do
end
end
describe
'detection of issues
to be closed
'
do
describe
'detection of issues'
do
let
(
:issue0
)
{
create
:issue
,
project:
subject
.
project
}
let
(
:issue1
)
{
create
:issue
,
project:
subject
.
project
}
...
...
@@ -265,29 +265,44 @@ describe MergeRequest, models: true do
allow
(
subject
).
to
receive
(
:commits
).
and_return
([
commit0
,
commit1
,
commit2
])
end
it
'accesses the set of issues that will be closed on acceptance'
do
allow
(
subject
.
project
).
to
receive
(
:default_branch
).
and_return
(
subject
.
target_branch
)
describe
'detection of issues to be closed'
do
it
'accesses the set of issues that will be closed on acceptance'
do
allow
(
subject
.
project
).
to
receive
(
:default_branch
).
and_return
(
subject
.
target_branch
)
closed
=
subject
.
closes_issues
closed
=
subject
.
closes_issues
expect
(
closed
).
to
include
(
issue0
,
issue1
)
end
expect
(
closed
).
to
include
(
issue0
,
issue1
)
end
it
'only lists issues as to be closed if it targets the default branch'
do
allow
(
subject
.
project
).
to
receive
(
:default_branch
).
and_return
(
'master'
)
subject
.
target_branch
=
'something-else'
expect
(
subject
.
closes_issues
).
to
be_empty
end
it
'detects issues mentioned in the description'
do
issue2
=
create
(
:issue
,
project:
subject
.
project
)
subject
.
description
=
"Closes
#{
issue2
.
to_reference
}
"
it
'only lists issues as to be closed if it targets the default branch'
do
allow
(
subject
.
project
).
to
receive
(
:default_branch
).
and_return
(
'master'
)
subject
.
target_branch
=
'something-else'
allow
(
subject
.
project
).
to
receive
(
:default_branch
).
and_return
(
subject
.
target_branch
)
expect
(
subject
.
closes_issues
).
to
be_empty
expect
(
subject
.
closes_issues
).
to
include
(
issue2
)
end
end
it
'detects issues mentioned in the description'
do
issue2
=
create
(
:issue
,
project:
subject
.
project
)
subject
.
description
=
"Closes
#{
issue2
.
to_reference
}
"
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
.
closes_issues
).
to
include
(
issue2
)
expect
(
subject
.
issues_mentioned_but_not_closing
).
to
match_array
([
mentioned_issue
]
)
end
end
...
...
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