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
1b843ee1
Commit
1b843ee1
authored
Oct 06, 2021
by
Daniel Diniz
Committed by
Tetiana Chupryna
Oct 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix branches being imported from closed and merged fork MRs
parent
3239e63e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
8 deletions
+32
-8
lib/gitlab/import_export/merge_request_parser.rb
lib/gitlab/import_export/merge_request_parser.rb
+3
-1
spec/lib/gitlab/import_export/merge_request_parser_spec.rb
spec/lib/gitlab/import_export/merge_request_parser_spec.rb
+29
-7
No files found.
lib/gitlab/import_export/merge_request_parser.rb
View file @
1b843ee1
...
@@ -39,7 +39,9 @@ module Gitlab
...
@@ -39,7 +39,9 @@ module Gitlab
# created manually. Ignore failures so we get the merge request itself if
# created manually. Ignore failures so we get the merge request itself if
# the commits are missing.
# the commits are missing.
def
create_source_branch
def
create_source_branch
@project
.
repository
.
create_branch
(
@merge_request
.
source_branch
,
@diff_head_sha
)
if
@merge_request
.
open?
@project
.
repository
.
create_branch
(
@merge_request
.
source_branch
,
@diff_head_sha
)
end
rescue
StandardError
=>
err
rescue
StandardError
=>
err
Gitlab
::
Import
::
Logger
.
warn
(
Gitlab
::
Import
::
Logger
.
warn
(
message:
'Import warning: Failed to create source branch'
,
message:
'Import warning: Failed to create source branch'
,
...
...
spec/lib/gitlab/import_export/merge_request_parser_spec.rb
View file @
1b843ee1
...
@@ -13,9 +13,11 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do
...
@@ -13,9 +13,11 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
project
)
create
(
:merge_request
,
source_project:
forked_project
,
target_project:
project
)
end
end
let
(
:diff_head_sha
)
{
SecureRandom
.
hex
(
20
)
}
let
(
:parsed_merge_request
)
do
let
(
:parsed_merge_request
)
do
described_class
.
new
(
project
,
described_class
.
new
(
project
,
'abcd'
,
diff_head_sha
,
merge_request
,
merge_request
,
merge_request
.
as_json
).
parse!
merge_request
.
as_json
).
parse!
end
end
...
@@ -34,14 +36,34 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do
...
@@ -34,14 +36,34 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do
expect
(
project
.
repository
.
branch_exists?
(
parsed_merge_request
.
target_branch
)).
to
be
true
expect
(
project
.
repository
.
branch_exists?
(
parsed_merge_request
.
target_branch
)).
to
be
true
end
end
it
'parses a MR that has no source branch'
do
# Source and target branch are only created when: fork_merge_request
allow_next_instance_of
(
described_class
)
do
|
instance
|
context
'fork merge request'
do
allow
(
instance
).
to
receive
(
:branch_exists?
).
and_call_original
before
do
allow
(
instance
).
to
receive
(
:branch_exists?
).
with
(
merge_request
.
source_branch
).
and_return
(
false
)
allow_next_instance_of
(
described_class
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:fork_merge_request?
).
and_return
(
true
)
allow
(
instance
).
to
receive
(
:fork_merge_request?
).
and_return
(
true
)
end
end
it
'parses a MR that has no source branch'
do
allow_next_instance_of
(
described_class
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:branch_exists?
).
and_call_original
allow
(
instance
).
to
receive
(
:branch_exists?
).
with
(
merge_request
.
source_branch
).
and_return
(
false
)
end
expect
(
parsed_merge_request
).
to
eq
(
merge_request
)
end
end
expect
(
parsed_merge_request
).
to
eq
(
merge_request
)
it
'parses a MR that is closed'
do
merge_request
.
update!
(
state: :closed
,
source_branch:
'new_branch'
)
expect
(
project
.
repository
.
branch_exists?
(
parsed_merge_request
.
source_branch
)).
to
be
false
end
it
'parses a MR that is merged'
do
merge_request
.
update!
(
state: :merged
,
source_branch:
'new_branch'
)
expect
(
project
.
repository
.
branch_exists?
(
parsed_merge_request
.
source_branch
)).
to
be
false
end
end
end
context
'when the merge request has diffs'
do
context
'when the merge request has diffs'
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