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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
45bfadbc
Commit
45bfadbc
authored
Sep 30, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug when trying to cache closed issues from external issue trackers
parent
a1aea326
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
0 deletions
+65
-0
CHANGELOG
CHANGELOG
+1
-0
app/models/merge_request.rb
app/models/merge_request.rb
+4
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+24
-0
spec/services/merge_requests/merge_service_spec.rb
spec/services/merge_requests/merge_service_spec.rb
+36
-0
No files found.
CHANGELOG
View file @
45bfadbc
...
@@ -45,6 +45,7 @@ v 8.13.0 (unreleased)
...
@@ -45,6 +45,7 @@ v 8.13.0 (unreleased)
- Changed Slack service user referencing from full name to username (Sebastian Poxhofer)
- Changed Slack service user referencing from full name to username (Sebastian Poxhofer)
v 8.12.4 (unreleased)
v 8.12.4 (unreleased)
- Fix type mismatch bug when closing Jira issue
v 8.12.3
v 8.12.3
- Update Gitlab Shell to support low IO priority for storage moves
- Update Gitlab Shell to support low IO priority for storage moves
...
...
app/models/merge_request.rb
View file @
45bfadbc
...
@@ -523,9 +523,13 @@ class MergeRequest < ActiveRecord::Base
...
@@ -523,9 +523,13 @@ class MergeRequest < ActiveRecord::Base
# `MergeRequestsClosingIssues` model. This is a performance optimization.
# `MergeRequestsClosingIssues` model. This is a performance optimization.
# Calculating this information for a number of merge requests requires
# Calculating this information for a number of merge requests requires
# running `ReferenceExtractor` on each of them separately.
# 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
=
self
.
author
)
return
if
project
.
has_external_issue_tracker?
transaction
do
transaction
do
self
.
merge_requests_closing_issues
.
delete_all
self
.
merge_requests_closing_issues
.
delete_all
closes_issues
(
current_user
).
each
do
|
issue
|
closes_issues
(
current_user
).
each
do
|
issue
|
self
.
merge_requests_closing_issues
.
create!
(
issue:
issue
)
self
.
merge_requests_closing_issues
.
create!
(
issue:
issue
)
end
end
...
...
spec/models/merge_request_spec.rb
View file @
45bfadbc
...
@@ -86,6 +86,30 @@ describe MergeRequest, models: true do
...
@@ -86,6 +86,30 @@ describe MergeRequest, models: true do
end
end
end
end
describe
'#cache_merge_request_closes_issues!'
do
before
do
subject
.
project
.
team
<<
[
subject
.
author
,
:developer
]
subject
.
target_branch
=
subject
.
project
.
default_branch
end
it
'caches closed issues'
do
issue
=
create
:issue
,
project:
subject
.
project
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
)
end
it
'does not cache issues from external trackers'
do
subject
.
project
.
update_attribute
(
:has_external_issue_tracker
,
true
)
issue
=
ExternalIssue
.
new
(
'JIRA-123'
,
subject
.
project
)
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
)
end
end
describe
'#source_branch_sha'
do
describe
'#source_branch_sha'
do
let
(
:last_branch_commit
)
{
subject
.
source_project
.
repository
.
commit
(
subject
.
source_branch
)
}
let
(
:last_branch_commit
)
{
subject
.
source_project
.
repository
.
commit
(
subject
.
source_branch
)
}
...
...
spec/services/merge_requests/merge_service_spec.rb
View file @
45bfadbc
...
@@ -38,6 +38,42 @@ describe MergeRequests::MergeService, services: true do
...
@@ -38,6 +38,42 @@ describe MergeRequests::MergeService, services: true do
end
end
end
end
context
'closes related issues'
do
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
}
before
do
allow
(
project
).
to
receive
(
:default_branch
).
and_return
(
merge_request
.
target_branch
)
end
it
'closes GitLab issue tracker issues'
do
issue
=
create
:issue
,
project:
project
commit
=
double
(
'commit'
,
safe_message:
"Fixes
#{
issue
.
to_reference
}
"
)
allow
(
merge_request
).
to
receive
(
:commits
).
and_return
([
commit
])
service
.
execute
(
merge_request
)
expect
(
issue
.
reload
.
closed?
).
to
be_truthy
end
context
'with JIRA integration'
do
include
JiraServiceHelper
let
(
:jira_tracker
)
{
project
.
create_jira_service
}
before
{
jira_service_settings
}
it
'closes issues on JIRA issue tracker'
do
jira_issue
=
ExternalIssue
.
new
(
'JIRA-123'
,
project
)
commit
=
double
(
'commit'
,
safe_message:
"Fixes
#{
jira_issue
.
to_reference
}
"
)
allow
(
merge_request
).
to
receive
(
:commits
).
and_return
([
commit
])
expect_any_instance_of
(
JiraService
).
to
receive
(
:close_issue
).
with
(
merge_request
,
jira_issue
).
once
service
.
execute
(
merge_request
)
end
end
end
context
'closes related todos'
do
context
'closes related todos'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
assignee:
user
,
author:
user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
assignee:
user
,
author:
user
)
}
let
(
:project
)
{
merge_request
.
project
}
let
(
:project
)
{
merge_request
.
project
}
...
...
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