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
Léo-Paul Géneau
gitlab-ce
Commits
ac1634fa
Commit
ac1634fa
authored
Apr 19, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract a method to import issues/pull requests comments
parent
00e3d60c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
79 deletions
+33
-79
lib/github/import.rb
lib/github/import.rb
+33
-79
No files found.
lib/github/import.rb
View file @
ac1634fa
...
...
@@ -141,63 +141,11 @@ module Github
# Fetch review comments
review_comments_url
=
"/repos/
#{
owner
}
/
#{
repo
}
/pulls/
#{
pull_request
.
iid
}
/comments"
loop
do
review_comments
=
Github
::
Client
.
new
.
get
(
review_comments_url
)
ActiveRecord
::
Base
.
no_touching
do
review_comments
.
body
.
each
do
|
raw
|
begin
comment
=
Github
::
Representation
::
Comment
.
new
(
raw
)
note
=
Note
.
new
note
.
project_id
=
project
.
id
note
.
noteable
=
merge_request
note
.
note
=
comment
.
note
note
.
commit_id
=
comment
.
commit_id
note
.
line_code
=
comment
.
line_code
note
.
author_id
=
user_id
(
comment
.
author
,
project
.
creator_id
)
note
.
type
=
comment
.
type
note
.
created_at
=
comment
.
created_at
note
.
updated_at
=
comment
.
updated_at
note
.
save!
(
validate:
false
)
rescue
=>
e
error
(
:review_comment
,
comment
.
url
,
e
.
message
)
end
end
end
break
unless
review_comments_url
=
review_comments
.
rels
[
:next
]
end
fetch_comments
(
merge_request
,
:review_comment
,
review_comments_url
)
# Fetch comments
comments_url
=
"/repos/
#{
owner
}
/
#{
repo
}
/issues/
#{
pull_request
.
iid
}
/comments"
loop
do
comments
=
Github
::
Client
.
new
.
get
(
comments_url
)
ActiveRecord
::
Base
.
no_touching
do
comments
.
body
.
each
do
|
raw
|
begin
comment
=
Github
::
Representation
::
Comment
.
new
(
raw
)
note
=
Note
.
new
note
.
project_id
=
project
.
id
note
.
noteable
=
merge_request
note
.
note
=
comment
.
note
note
.
author_id
=
user_id
(
comment
.
author
,
project
.
creator_id
)
note
.
created_at
=
comment
.
created_at
note
.
updated_at
=
comment
.
updated_at
note
.
save!
(
validate:
false
)
rescue
=>
e
error
(
:comment
,
comment
.
url
,
e
.
message
)
end
end
end
break
unless
comments_url
=
comments
.
rels
[
:next
]
end
fetch_comments
(
merge_request
,
:comment
,
comments_url
)
rescue
=>
e
error
(
:pull_request
,
pull_request
.
url
,
e
.
message
)
ensure
...
...
@@ -247,47 +195,53 @@ module Github
if
representation
.
has_comments?
# Fetch comments
comments_url
=
"/repos/
#{
owner
}
/
#{
repo
}
/issues/
#{
issue
.
iid
}
/comments"
fetch_comments
(
issue
,
:comment
,
comments_url
)
end
end
rescue
=>
e
error
(
:issue
,
representation
.
url
,
e
.
message
)
end
end
break
unless
url
=
response
.
rels
[
:next
]
end
repository
.
expire_content_cache
errors
end
private
def
fetch_comments
(
noteable
,
type
,
url
)
loop
do
comments
=
Github
::
Client
.
new
.
get
(
comments_
url
)
comments
=
Github
::
Client
.
new
.
get
(
url
)
ActiveRecord
::
Base
.
no_touching
do
comments
.
body
.
each
do
|
raw
|
begin
comment
=
Github
::
Representation
::
Comment
.
new
(
raw
)
representation
=
Github
::
Representation
::
Comment
.
new
(
raw
)
note
=
Note
.
new
note
.
project_id
=
project
.
id
note
.
noteable
=
issue
note
.
note
=
comment
.
note
note
.
author_id
=
user_id
(
comment
.
author
,
project
.
creator_id
)
note
.
created_at
=
comment
.
created_at
note
.
updated_at
=
comment
.
updated_at
note
.
noteable
=
noteable
note
.
note
=
representation
.
note
note
.
commit_id
=
representation
.
commit_id
note
.
line_code
=
representation
.
line_code
note
.
author_id
=
user_id
(
representation
.
author
,
project
.
creator_id
)
note
.
type
=
representation
.
type
note
.
created_at
=
representation
.
created_at
note
.
updated_at
=
representation
.
updated_at
note
.
save!
(
validate:
false
)
rescue
=>
e
error
(
:comment
,
comment
.
url
,
e
.
message
)
error
(
type
,
representation
.
url
,
e
.
message
)
end
end
end
break
unless
comments_
url
=
comments
.
rels
[
:next
]
break
unless
url
=
comments
.
rels
[
:next
]
end
end
end
rescue
=>
e
error
(
:issue
,
representation
.
url
,
e
.
message
)
end
end
break
unless
url
=
response
.
rels
[
:next
]
end
repository
.
expire_content_cache
errors
end
private
def
restore_source_branch
(
pull_request
)
repository
.
create_branch
(
pull_request
.
source_branch_name
,
pull_request
.
source_branch_sha
)
...
...
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