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
Boxiang Sun
gitlab-ce
Commits
8532dc0d
Commit
8532dc0d
authored
Apr 21, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import pull requests from GitHub where the source branch was removed
parent
61756ecc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
27 deletions
+47
-27
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+30
-18
lib/gitlab/github_import/pull_request_formatter.rb
lib/gitlab/github_import/pull_request_formatter.rb
+17
-9
No files found.
lib/gitlab/github_import/importer.rb
View file @
8532dc0d
...
@@ -3,12 +3,15 @@ module Gitlab
...
@@ -3,12 +3,15 @@ module Gitlab
class
Importer
class
Importer
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
attr_reader
:
project
,
:client
attr_reader
:
client
,
:project
,
:repo
,
:repo_url
def
initialize
(
project
)
def
initialize
(
project
)
@project
=
project
@project
=
project
if
import_data_credentials
@repo
=
project
.
import_source
@client
=
Client
.
new
(
import_data_credentials
[
:user
])
@repo_url
=
project
.
import_url
if
credentials
@client
=
Client
.
new
(
credentials
[
:user
])
@formatter
=
Gitlab
::
ImportFormatter
.
new
@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
}
"
...
@@ -22,8 +25,8 @@ module Gitlab
...
@@ -22,8 +25,8 @@ module Gitlab
private
private
def
import_data_
credentials
def
credentials
@
import_data_
credentials
||=
project
.
import_data
.
credentials
if
project
.
import_data
@credentials
||=
project
.
import_data
.
credentials
if
project
.
import_data
end
end
def
import_labels
def
import_labels
...
@@ -68,22 +71,31 @@ module Gitlab
...
@@ -68,22 +71,31 @@ module Gitlab
end
end
def
import_pull_requests
def
import_pull_requests
client
.
pull_requests
(
project
.
import_source
,
state: :all
,
pull_requests
=
client
.
pull_requests
(
repo
,
state: :all
,
sort: :created
,
direction: :asc
)
sort: :created
,
.
map
{
|
raw
|
PullRequestFormatter
.
new
(
project
,
raw
)
}
direction: :asc
).
each
do
|
raw_data
|
.
reject
(
&
:cross_project?
)
pull_request
=
PullRequestFormatter
.
new
(
project
,
raw_data
)
source_branches_removed
=
pull_requests
.
reject
(
&
:source_branch_exists?
)
if
pull_request
.
valid?
source_branches_removed
.
each
do
|
pull_request
|
merge_request
=
MergeRequest
.
new
(
pull_request
.
attributes
)
client
.
create_ref
(
repo
,
"refs/heads/
#{
pull_request
.
source_branch
}
"
,
pull_request
.
source_sha
)
end
if
merge_request
.
save
apply_labels
(
pull_request
.
number
,
merge_request
)
project
.
repository
.
fetch_ref
(
repo_url
,
'+refs/heads/*'
,
'refs/heads/*'
)
import_comments
(
pull_request
.
number
,
merge_request
)
import_comments_on_diff
(
pull_request
.
number
,
merge_request
)
pull_requests
.
each
do
|
pull_request
|
end
merge_request
=
MergeRequest
.
new
(
pull_request
.
attributes
)
if
merge_request
.
save
apply_labels
(
pull_request
.
number
,
merge_request
)
import_comments
(
pull_request
.
number
,
merge_request
)
import_comments_on_diff
(
pull_request
.
number
,
merge_request
)
end
end
end
end
source_branches_removed
.
each
do
|
pull_request
|
client
.
delete_ref
(
repo
,
"heads/
#{
pull_request
.
source_branch
}
"
)
end
true
true
rescue
ActiveRecord
::
RecordInvalid
=>
e
rescue
ActiveRecord
::
RecordInvalid
=>
e
raise
Projects
::
ImportService
::
Error
,
e
.
message
raise
Projects
::
ImportService
::
Error
,
e
.
message
...
...
lib/gitlab/github_import/pull_request_formatter.rb
View file @
8532dc0d
...
@@ -7,7 +7,7 @@ module Gitlab
...
@@ -7,7 +7,7 @@ module Gitlab
title:
raw_data
.
title
,
title:
raw_data
.
title
,
description:
description
,
description:
description
,
source_project:
source_project
,
source_project:
source_project
,
source_branch:
source_branch
.
name
,
source_branch:
source_branch
,
target_project:
target_project
,
target_project:
target_project
,
target_branch:
target_branch
.
name
,
target_branch:
target_branch
.
name
,
state:
state
,
state:
state
,
...
@@ -27,6 +27,22 @@ module Gitlab
...
@@ -27,6 +27,22 @@ module Gitlab
!
cross_project?
&&
source_branch
.
present?
&&
target_branch
.
present?
!
cross_project?
&&
source_branch
.
present?
&&
target_branch
.
present?
end
end
def
cross_project?
source_repo
.
present?
&&
target_repo
.
present?
&&
source_repo
.
id
!=
target_repo
.
id
end
def
source_branch_exists?
source_project
.
repository
.
branch_names
.
include?
(
source_branch
)
end
def
source_branch
raw_data
.
head
.
ref
end
def
source_sha
raw_data
.
head
.
sha
end
private
private
def
assigned?
def
assigned?
...
@@ -51,10 +67,6 @@ module Gitlab
...
@@ -51,10 +67,6 @@ module Gitlab
raw_data
.
body
||
""
raw_data
.
body
||
""
end
end
def
cross_project?
source_repo
.
present?
&&
target_repo
.
present?
&&
source_repo
.
id
!=
target_repo
.
id
end
def
description
def
description
formatter
.
author_line
(
author
)
+
body
formatter
.
author_line
(
author
)
+
body
end
end
...
@@ -73,10 +85,6 @@ module Gitlab
...
@@ -73,10 +85,6 @@ module Gitlab
raw_data
.
head
.
repo
raw_data
.
head
.
repo
end
end
def
source_branch
source_project
.
repository
.
find_branch
(
raw_data
.
head
.
ref
)
end
def
target_project
def
target_project
project
project
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