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
95f1fe72
Commit
95f1fe72
authored
Dec 21, 2015
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import GitHub Pull Requests into GitLab
parent
8de1f715
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
7 deletions
+57
-7
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+57
-7
No files found.
lib/gitlab/github_import/importer.rb
View file @
95f1fe72
...
@@ -12,7 +12,16 @@ module Gitlab
...
@@ -12,7 +12,16 @@ module Gitlab
end
end
def
execute
def
execute
#Issues && Comments
import_issues
import_pull_requests
true
end
private
def
import_issues
# Issues && Comments
client
.
list_issues
(
project
.
import_source
,
state: :all
,
client
.
list_issues
(
project
.
import_source
,
state: :all
,
sort: :created
,
sort: :created
,
direction: :asc
).
each
do
|
issue
|
direction: :asc
).
each
do
|
issue
|
...
@@ -33,18 +42,59 @@ module Gitlab
...
@@ -33,18 +42,59 @@ module Gitlab
description:
body
,
description:
body
,
title:
issue
.
title
,
title:
issue
.
title
,
state:
issue
.
state
==
'closed'
?
'closed'
:
'opened'
,
state:
issue
.
state
==
'closed'
?
'closed'
:
'opened'
,
author_id:
gl_
use
r_id
(
project
,
issue
.
user
.
id
)
author_id:
gl_
autho
r_id
(
project
,
issue
.
user
.
id
)
)
)
end
end
end
end
end
end
private
def
import_pull_requests
client
.
pull_requests
(
project
.
import_source
,
state: :all
,
sort: :created
,
direction: :asc
).
each
do
|
pull_request
|
body
=
@formatter
.
author_line
(
pull_request
.
user
.
login
)
body
+=
pull_request
.
body
||
""
source_branch
=
pull_request
.
head
.
ref
target_branch
=
pull_request
.
base
.
ref
merge_request
=
MergeRequest
.
create!
(
title:
pull_request
.
title
,
description:
body
,
source_project:
project
,
source_branch:
source_branch
,
target_project:
project
,
target_branch:
target_branch
,
state:
merge_request_state
(
pull_request
),
author_id:
gl_author_id
(
project
,
pull_request
.
user
.
id
),
assignee_id:
gl_user_id
(
pull_request
.
assignee
.
try
(
:id
)),
created_at:
pull_request
.
created_at
,
updated_at:
pull_request
.
updated_at
)
end
end
def
merge_request_state
(
pull_request
)
case
true
when
pull_request
.
state
==
'closed'
&&
pull_request
.
merged_at
.
present?
'merged'
when
pull_request
.
state
==
'closed'
'closed'
else
'opened'
end
end
def
gl_author_id
(
project
,
github_id
)
gl_user_id
(
github_id
)
||
project
.
creator_id
end
def
gl_user_id
(
project
,
github_id
)
def
gl_user_id
(
github_id
)
user
=
User
.
joins
(
:identities
).
if
github_id
find_by
(
"identities.extern_uid = ? AND identities.provider = 'github'"
,
github_id
.
to_s
)
User
.
joins
(
:identities
).
(
user
&&
user
.
id
)
||
project
.
creator_id
find_by
(
"identities.extern_uid = ? AND identities.provider = 'github'"
,
github_id
.
to_s
).
try
(
:id
)
end
end
end
end
end
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