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
796f531f
Commit
796f531f
authored
Oct 04, 2016
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_22446' into 'master'
Fix bug when trying to cache closed issues from external issue trackers fixes #22446 See merge request !6619
parents
8c280b1c
a97280ea
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
0 deletions
+65
-0
CHANGELOG
CHANGELOG
+1
-0
merge_request.rb
app/models/merge_request.rb
+4
-0
merge_request_spec.rb
spec/models/merge_request_spec.rb
+24
-0
merge_service_spec.rb
spec/services/merge_requests/merge_service_spec.rb
+36
-0
No files found.
CHANGELOG
View file @
796f531f
...
...
@@ -48,6 +48,7 @@ v 8.13.0 (unreleased)
- Add Container Registry on/off status to Admin Area !6638 (the-undefined)
v 8.12.4 (unreleased)
- Fix type mismatch bug when closing Jira issue
- Fix issues importing services via Import/Export
- Fix "Copy to clipboard" tooltip to say "Copied!" when clipboard button is clicked. (lukehowell)
...
...
app/models/merge_request.rb
View file @
796f531f
...
...
@@ -523,9 +523,13 @@ class MergeRequest < ActiveRecord::Base
# `MergeRequestsClosingIssues` model. This is a performance optimization.
# 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
)
return
if
project
.
has_external_issue_tracker?
transaction
do
self
.
merge_requests_closing_issues
.
delete_all
closes_issues
(
current_user
).
each
do
|
issue
|
self
.
merge_requests_closing_issues
.
create!
(
issue:
issue
)
end
...
...
spec/models/merge_request_spec.rb
View file @
796f531f
...
...
@@ -86,6 +86,30 @@ describe MergeRequest, models: true do
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
let
(
:last_branch_commit
)
{
subject
.
source_project
.
repository
.
commit
(
subject
.
source_branch
)
}
...
...
spec/services/merge_requests/merge_service_spec.rb
View file @
796f531f
...
...
@@ -38,6 +38,42 @@ describe MergeRequests::MergeService, services: true do
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
let
(
:merge_request
)
{
create
(
:merge_request
,
assignee:
user
,
author:
user
)
}
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