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
40704daa
Commit
40704daa
authored
Feb 08, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'restore-issues_mentioned_but_not_closing' into 'master'
pass in current_user in MergeRequest and MergeRequestsHelper See merge request !8624
parents
89a15bec
bbbef273
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
12 deletions
+94
-12
merge_requests_helper.rb
app/helpers/merge_requests_helper.rb
+2
-2
merge_request.rb
app/models/merge_request.rb
+3
-7
pass in current_user in MergeRequest and MergeRequestsHelper.yml
... current_user in MergeRequest and MergeRequestsHelper.yml
+4
-0
merge_requests_helper_spec.rb
spec/helpers/merge_requests_helper_spec.rb
+82
-0
merge_request_spec.rb
spec/models/merge_request_spec.rb
+3
-3
No files found.
app/helpers/merge_requests_helper.rb
View file @
40704daa
...
...
@@ -64,11 +64,11 @@ module MergeRequestsHelper
end
def
mr_closes_issues
@mr_closes_issues
||=
@merge_request
.
closes_issues
@mr_closes_issues
||=
@merge_request
.
closes_issues
(
current_user
)
end
def
mr_issues_mentioned_but_not_closing
@mr_issues_mentioned_but_not_closing
||=
@merge_request
.
issues_mentioned_but_not_closing
@mr_issues_mentioned_but_not_closing
||=
@merge_request
.
issues_mentioned_but_not_closing
(
current_user
)
end
def
mr_change_branches_path
(
merge_request
)
...
...
app/models/merge_request.rb
View file @
40704daa
...
...
@@ -546,7 +546,7 @@ class MergeRequest < ActiveRecord::Base
# Calculating this information for a number of merge requests requires
# running `ReferenceExtractor` on each of them separately.
# This optimization does not apply to issues from external sources.
def
cache_merge_request_closes_issues!
(
current_user
=
self
.
author
)
def
cache_merge_request_closes_issues!
(
current_user
)
return
if
project
.
has_external_issue_tracker?
transaction
do
...
...
@@ -558,10 +558,6 @@ class MergeRequest < ActiveRecord::Base
end
end
def
closes_issue?
(
issue
)
closes_issues
.
include?
(
issue
)
end
# Return the set of issues that will be closed if this merge request is accepted.
def
closes_issues
(
current_user
=
self
.
author
)
if
target_branch
==
project
.
default_branch
...
...
@@ -575,13 +571,13 @@ class MergeRequest < ActiveRecord::Base
end
end
def
issues_mentioned_but_not_closing
(
current_user
=
self
.
author
)
def
issues_mentioned_but_not_closing
(
current_user
)
return
[]
unless
target_branch
==
project
.
default_branch
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
project
,
current_user
)
ext
.
analyze
(
description
)
ext
.
issues
-
closes_issues
ext
.
issues
-
closes_issues
(
current_user
)
end
def
target_project_path
...
...
changelogs/unreleased/pass in current_user in MergeRequest and MergeRequestsHelper.yml
0 → 100644
View file @
40704daa
---
title
:
pass in current_user in MergeRequest and MergeRequestsHelper
merge_request
:
8624
author
:
Dongqing Hu
spec/helpers/merge_requests_helper_spec.rb
View file @
40704daa
...
...
@@ -79,4 +79,86 @@ describe MergeRequestsHelper do
expect
(
mr_widget_refresh_url
(
nil
)).
to
eq
(
''
)
end
end
describe
'#mr_closes_issues'
do
let
(
:user_1
)
{
create
(
:user
)
}
let
(
:user_2
)
{
create
(
:user
)
}
let
(
:project_1
)
{
create
(
:project
,
:private
,
creator:
user_1
,
namespace:
user_1
.
namespace
)
}
let
(
:project_2
)
{
create
(
:project
,
:private
,
creator:
user_2
,
namespace:
user_2
.
namespace
)
}
let
(
:issue_1
)
{
create
(
:issue
,
project:
project_1
)
}
let
(
:issue_2
)
{
create
(
:issue
,
project:
project_2
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project_1
,
target_project:
project_1
,)
}
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project_1
,
target_project:
project_1
,
description:
"Fixes
#{
issue_1
.
to_reference
}
Fixes
#{
issue_2
.
to_reference
(
project_1
)
}
"
)
end
before
do
project_1
.
team
<<
[
user_2
,
:developer
]
project_2
.
team
<<
[
user_2
,
:developer
]
allow
(
merge_request
.
project
).
to
receive
(
:default_branch
).
and_return
(
merge_request
.
target_branch
)
@merge_request
=
merge_request
end
context
'user without access to another private project'
do
let
(
:current_user
)
{
user_1
}
it
'cannot see that project\'s issue that will be closed on acceptance'
do
expect
(
mr_closes_issues
).
to
contain_exactly
(
issue_1
)
end
end
context
'user with access to another private project'
do
let
(
:current_user
)
{
user_2
}
it
'can see that project\'s issue that will be closed on acceptance'
do
expect
(
mr_closes_issues
).
to
contain_exactly
(
issue_1
,
issue_2
)
end
end
end
describe
'#mr_issues_mentioned_but_not_closing'
do
let
(
:user_1
)
{
create
(
:user
)
}
let
(
:user_2
)
{
create
(
:user
)
}
let
(
:project_1
)
{
create
(
:project
,
:private
,
creator:
user_1
,
namespace:
user_1
.
namespace
)
}
let
(
:project_2
)
{
create
(
:project
,
:private
,
creator:
user_2
,
namespace:
user_2
.
namespace
)
}
let
(
:issue_1
)
{
create
(
:issue
,
project:
project_1
)
}
let
(
:issue_2
)
{
create
(
:issue
,
project:
project_2
)
}
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project_1
,
target_project:
project_1
,
description:
"
#{
issue_1
.
to_reference
}
#{
issue_2
.
to_reference
(
project_1
)
}
"
)
end
before
do
project_1
.
team
<<
[
user_2
,
:developer
]
project_2
.
team
<<
[
user_2
,
:developer
]
allow
(
merge_request
.
project
).
to
receive
(
:default_branch
).
and_return
(
merge_request
.
target_branch
)
@merge_request
=
merge_request
end
context
'user without access to another private project'
do
let
(
:current_user
)
{
user_1
}
it
'cannot see that project\'s issue that will be closed on acceptance'
do
expect
(
mr_issues_mentioned_but_not_closing
).
to
contain_exactly
(
issue_1
)
end
end
context
'user with access to another private project'
do
let
(
:current_user
)
{
user_2
}
it
'can see that project\'s issue that will be closed on acceptance'
do
expect
(
mr_issues_mentioned_but_not_closing
).
to
contain_exactly
(
issue_1
,
issue_2
)
end
end
end
end
spec/models/merge_request_spec.rb
View file @
40704daa
...
...
@@ -97,7 +97,7 @@ describe MergeRequest, models: true do
commit
=
double
(
'commit1'
,
safe_message:
"Fixes
#{
issue
.
to_reference
}
"
)
allow
(
subject
).
to
receive
(
:commits
).
and_return
([
commit
])
expect
{
subject
.
cache_merge_request_closes_issues!
}.
to
change
(
subject
.
merge_requests_closing_issues
,
:count
).
by
(
1
)
expect
{
subject
.
cache_merge_request_closes_issues!
(
subject
.
author
)
}.
to
change
(
subject
.
merge_requests_closing_issues
,
:count
).
by
(
1
)
end
it
'does not cache issues from external trackers'
do
...
...
@@ -106,7 +106,7 @@ describe MergeRequest, models: true do
commit
=
double
(
'commit1'
,
safe_message:
"Fixes
#{
issue
.
to_reference
}
"
)
allow
(
subject
).
to
receive
(
:commits
).
and_return
([
commit
])
expect
{
subject
.
cache_merge_request_closes_issues!
}.
not_to
change
(
subject
.
merge_requests_closing_issues
,
:count
)
expect
{
subject
.
cache_merge_request_closes_issues!
(
subject
.
author
)
}.
not_to
change
(
subject
.
merge_requests_closing_issues
,
:count
)
end
end
...
...
@@ -300,7 +300,7 @@ describe MergeRequest, models: true do
allow
(
subject
.
project
).
to
receive
(
:default_branch
).
and_return
(
subject
.
target_branch
)
expect
(
subject
.
issues_mentioned_but_not_closing
).
to
match_array
([
mentioned_issue
])
expect
(
subject
.
issues_mentioned_but_not_closing
(
subject
.
author
)
).
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