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
e30bfb80
Commit
e30bfb80
authored
Sep 27, 2016
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import all GitHub comments after importing issues and PRs
parent
dbcbbf26
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+15
-12
spec/lib/gitlab/github_import/importer_spec.rb
spec/lib/gitlab/github_import/importer_spec.rb
+2
-0
No files found.
lib/gitlab/github_import/importer.rb
View file @
e30bfb80
...
@@ -24,6 +24,7 @@ module Gitlab
...
@@ -24,6 +24,7 @@ module Gitlab
import_milestones
import_milestones
import_issues
import_issues
import_pull_requests
import_pull_requests
import_comments
import_wiki
import_wiki
import_releases
import_releases
handle_errors
handle_errors
...
@@ -80,7 +81,6 @@ module Gitlab
...
@@ -80,7 +81,6 @@ module Gitlab
begin
begin
issue
=
gh_issue
.
create!
issue
=
gh_issue
.
create!
apply_labels
(
issue
,
raw
)
apply_labels
(
issue
,
raw
)
import_comments
(
issue
)
if
gh_issue
.
has_comments?
rescue
=>
e
rescue
=>
e
errors
<<
{
type: :issue
,
url:
Gitlab
::
UrlSanitizer
.
sanitize
(
raw
.
url
),
errors:
e
.
message
}
errors
<<
{
type: :issue
,
url:
Gitlab
::
UrlSanitizer
.
sanitize
(
raw
.
url
),
errors:
e
.
message
}
end
end
...
@@ -101,8 +101,6 @@ module Gitlab
...
@@ -101,8 +101,6 @@ module Gitlab
merge_request
=
pull_request
.
create!
merge_request
=
pull_request
.
create!
apply_labels
(
merge_request
,
raw
)
apply_labels
(
merge_request
,
raw
)
import_comments
(
merge_request
)
import_comments_on_diff
(
merge_request
)
rescue
=>
e
rescue
=>
e
errors
<<
{
type: :pull_request
,
url:
Gitlab
::
UrlSanitizer
.
sanitize
(
pull_request
.
url
),
errors:
e
.
message
}
errors
<<
{
type: :pull_request
,
url:
Gitlab
::
UrlSanitizer
.
sanitize
(
pull_request
.
url
),
errors:
e
.
message
}
ensure
ensure
...
@@ -143,21 +141,26 @@ module Gitlab
...
@@ -143,21 +141,26 @@ module Gitlab
end
end
end
end
def
import_comments
(
issuable
)
def
import_comments
c
omments
=
client
.
issue_comments
(
repo
,
issuable
.
iid
,
per_page:
100
)
c
lient
.
issues_comments
(
repo
,
per_page:
100
)
do
|
comments
|
create_comments
(
issuable
,
comments
)
create_comments
(
comments
,
:issue
)
end
end
def
import_comments_on_diff
(
merge_request
)
client
.
pull_requests_comments
(
repo
,
per_page:
100
)
do
|
comments
|
comments
=
client
.
pull_request_comments
(
repo
,
merge_request
.
iid
,
per_page:
100
)
create_comments
(
comments
,
:pull_request
)
create_comments
(
merge_request
,
comments
)
end
end
end
def
create_comments
(
issuable
,
comments
)
def
create_comments
(
comments
,
issuable_type
)
ActiveRecord
::
Base
.
no_touching
do
ActiveRecord
::
Base
.
no_touching
do
comments
.
each
do
|
raw
|
comments
.
each
do
|
raw
|
begin
begin
comment
=
CommentFormatter
.
new
(
project
,
raw
)
comment
=
CommentFormatter
.
new
(
project
,
raw
)
issuable_class
=
issuable_type
==
:issue
?
Issue
:
MergeRequest
iid
=
raw
.
send
(
"
#{
issuable_type
}
_url"
).
split
(
'/'
).
last
# GH doesn't return parent ID directly
issuable
=
issuable_class
.
find_by_iid
(
iid
)
next
unless
issuable
issuable
.
notes
.
create!
(
comment
.
attributes
)
issuable
.
notes
.
create!
(
comment
.
attributes
)
rescue
=>
e
rescue
=>
e
errors
<<
{
type: :comment
,
url:
Gitlab
::
UrlSanitizer
.
sanitize
(
raw
.
url
),
errors:
e
.
message
}
errors
<<
{
type: :comment
,
url:
Gitlab
::
UrlSanitizer
.
sanitize
(
raw
.
url
),
errors:
e
.
message
}
...
...
spec/lib/gitlab/github_import/importer_spec.rb
View file @
e30bfb80
...
@@ -132,6 +132,8 @@ describe Gitlab::GithubImport::Importer, lib: true do
...
@@ -132,6 +132,8 @@ describe Gitlab::GithubImport::Importer, lib: true do
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:milestones
).
and_return
([
milestone
,
milestone
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:milestones
).
and_return
([
milestone
,
milestone
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:issues
).
and_return
([
issue1
,
issue2
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:issues
).
and_return
([
issue1
,
issue2
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:pull_requests
).
and_return
([
pull_request
,
pull_request
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:pull_requests
).
and_return
([
pull_request
,
pull_request
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:issues_comments
).
and_return
([])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:pull_requests_comments
).
and_return
([])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:last_response
).
and_return
(
double
(
rels:
{
next:
nil
}))
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:last_response
).
and_return
(
double
(
rels:
{
next:
nil
}))
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:releases
).
and_return
([
release1
,
release2
])
allow_any_instance_of
(
Octokit
::
Client
).
to
receive
(
:releases
).
and_return
([
release1
,
release2
])
allow_any_instance_of
(
Gitlab
::
Shell
).
to
receive
(
:import_repository
).
and_raise
(
Gitlab
::
Shell
::
Error
)
allow_any_instance_of
(
Gitlab
::
Shell
).
to
receive
(
:import_repository
).
and_raise
(
Gitlab
::
Shell
::
Error
)
...
...
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