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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
167a0c7f
Commit
167a0c7f
authored
Aug 04, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove SHA suffix for removed branches name when importing PR from GH
parent
1e736fb5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
36 deletions
+28
-36
lib/gitlab/github_import/branch_formatter.rb
lib/gitlab/github_import/branch_formatter.rb
+1
-1
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+26
-28
spec/lib/gitlab/github_import/branch_formatter_spec.rb
spec/lib/gitlab/github_import/branch_formatter_spec.rb
+1
-7
No files found.
lib/gitlab/github_import/branch_formatter.rb
View file @
167a0c7f
...
@@ -8,7 +8,7 @@ module Gitlab
...
@@ -8,7 +8,7 @@ module Gitlab
end
end
def
name
def
name
@name
||=
exists?
?
ref
:
"
#{
ref
}
-
#{
short_id
}
"
ref
end
end
def
valid?
def
valid?
...
...
lib/gitlab/github_import/importer.rb
View file @
167a0c7f
...
@@ -12,7 +12,6 @@ module Gitlab
...
@@ -12,7 +12,6 @@ module Gitlab
if
credentials
if
credentials
@client
=
Client
.
new
(
credentials
[
:user
])
@client
=
Client
.
new
(
credentials
[
:user
])
@formatter
=
Gitlab
::
ImportFormatter
.
new
else
else
raise
Projects
::
ImportService
::
Error
,
"Unable to find project import data credentials for project ID:
#{
@project
.
id
}
"
raise
Projects
::
ImportService
::
Error
,
"Unable to find project import data credentials for project ID:
#{
@project
.
id
}
"
end
end
...
@@ -69,44 +68,43 @@ module Gitlab
...
@@ -69,44 +68,43 @@ module Gitlab
pull_requests
=
client
.
pull_requests
(
repo
,
state: :all
,
sort: :created
,
direction: :asc
,
per_page:
100
)
pull_requests
=
client
.
pull_requests
(
repo
,
state: :all
,
sort: :created
,
direction: :asc
,
per_page:
100
)
pull_requests
=
pull_requests
.
map
{
|
raw
|
PullRequestFormatter
.
new
(
project
,
raw
)
}.
select
(
&
:valid?
)
pull_requests
=
pull_requests
.
map
{
|
raw
|
PullRequestFormatter
.
new
(
project
,
raw
)
}.
select
(
&
:valid?
)
source_branches_removed
=
pull_requests
.
reject
(
&
:source_branch_exists?
).
map
{
|
pr
|
[
pr
.
source_branch_name
,
pr
.
number
]
}
target_branches_removed
=
pull_requests
.
reject
(
&
:target_branch_exists?
).
map
{
|
pr
|
[
pr
.
target_branch_name
,
pr
.
target_branch_sha
]
}
branches_removed
=
source_branches_removed
|
target_branches_removed
restore_source_branches
(
source_branches_removed
)
restore_target_branches
(
target_branches_removed
)
pull_requests
.
each
do
|
pull_request
|
pull_requests
.
each
do
|
pull_request
|
begin
restore_source_branch
(
pull_request
)
unless
pull_request
.
source_branch_exists?
restore_target_branch
(
pull_request
)
unless
pull_request
.
target_branch_exists?
merge_request
=
pull_request
.
create!
merge_request
=
pull_request
.
create!
apply_labels
(
merge_request
)
apply_labels
(
merge_request
)
import_comments
(
merge_request
)
import_comments
(
merge_request
)
import_comments_on_diff
(
merge_request
)
import_comments_on_diff
(
merge_request
)
end
true
rescue
ActiveRecord
::
RecordInvalid
=>
e
rescue
ActiveRecord
::
RecordInvalid
=>
e
raise
Projects
::
ImportService
::
Error
,
e
.
message
raise
Projects
::
ImportService
::
Error
,
e
.
message
ensure
ensure
clean_up_restored_branches
(
branches_removed
)
clean_up_restored_branches
(
pull_request
)
end
end
def
restore_source_branches
(
branches
)
branches
.
each
do
|
name
,
number
|
project
.
repository
.
fetch_ref
(
repo_url
,
"pull/
#{
number
}
/head"
,
name
)
end
end
true
end
end
def
restore_target_branches
(
branches
)
def
restore_source_branch
(
pull_request
)
branches
.
each
do
|
name
,
sha
|
project
.
repository
.
fetch_ref
(
repo_url
,
"pull/
#{
pull_request
.
number
}
/head"
,
pull_request
.
source_branch_name
)
project
.
repository
.
create_branch
(
name
,
sha
)
end
end
def
restore_target_branch
(
pull_request
)
project
.
repository
.
create_branch
(
pull_request
.
target_branch_name
,
pull_request
.
target_branch_sha
)
end
end
def
clean_up_restored_branches
(
branches
)
def
remove_branch
(
name
)
branches
.
each
do
|
name
,
_
|
project
.
repository
.
delete_branch
(
name
)
project
.
repository
.
delete_branch
(
name
)
rescue
Rugged
::
ReferenceError
rescue
Rugged
::
ReferenceError
nil
end
end
def
clean_up_restored_branches
(
pull_request
)
remove_branch
(
pull_request
.
source_branch_name
)
unless
pull_request
.
source_branch_exists?
remove_branch
(
pull_request
.
target_branch_name
)
unless
pull_request
.
target_branch_exists?
project
.
repository
.
after_remove_branch
project
.
repository
.
after_remove_branch
end
end
...
...
spec/lib/gitlab/github_import/branch_formatter_spec.rb
View file @
167a0c7f
...
@@ -33,17 +33,11 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
...
@@ -33,17 +33,11 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
end
end
describe
'#name'
do
describe
'#name'
do
it
'returns raw ref
when branch exists
'
do
it
'returns raw ref'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
))
branch
=
described_class
.
new
(
project
,
double
(
raw
))
expect
(
branch
.
name
).
to
eq
'feature'
expect
(
branch
.
name
).
to
eq
'feature'
end
end
it
'returns formatted ref when branch does not exist'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
.
merge
(
ref:
'removed-branch'
,
sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
)))
expect
(
branch
.
name
).
to
eq
'removed-branch-2e5d3239'
end
end
end
describe
'#repo'
do
describe
'#repo'
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