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
ea393e6f
Commit
ea393e6f
authored
Nov 16, 2016
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import pull request comments
parent
489d241c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
1 deletion
+115
-1
lib/bitbucket/client.rb
lib/bitbucket/client.rb
+7
-0
lib/bitbucket/representation/pull_request_comment.rb
lib/bitbucket/representation/pull_request_comment.rb
+39
-0
lib/gitlab/bitbucket_import/importer.rb
lib/gitlab/bitbucket_import/importer.rb
+69
-1
No files found.
lib/bitbucket/client.rb
View file @
ea393e6f
...
...
@@ -28,6 +28,13 @@ module Bitbucket
Collection
.
new
(
paginator
)
end
def
pull_request_comments
(
repo
,
pull_request
)
relative_path
=
"/repositories/
#{
repo
}
/pullrequests/
#{
pull_request
}
/comments"
paginator
=
Paginator
.
new
(
connection
,
relative_path
,
:pull_request_comment
)
Collection
.
new
(
paginator
)
end
def
repo
(
name
)
parsed_response
=
connection
.
get
(
"/repositories/
#{
name
}
"
)
Representation
::
Repo
.
new
(
parsed_response
)
...
...
lib/bitbucket/representation/pull_request_comment.rb
0 → 100644
View file @
ea393e6f
module
Bitbucket
module
Representation
class
PullRequestComment
<
Comment
def
iid
raw
[
'id'
]
end
def
file_path
inline
.
fetch
(
'path'
,
nil
)
end
def
old_pos
inline
.
fetch
(
'from'
,
nil
)
||
1
end
def
new_pos
inline
.
fetch
(
'to'
,
nil
)
||
1
end
def
parent_id
raw
.
fetch
(
'parent'
,
{}).
fetch
(
'id'
,
nil
)
end
def
inline?
raw
.
has_key?
(
'inline'
)
end
def
has_parent?
raw
.
has_key?
(
'parent'
)
end
private
def
inline
raw
.
fetch
(
'inline'
,
{})
end
end
end
end
lib/gitlab/bitbucket_import/importer.rb
View file @
ea393e6f
...
...
@@ -82,7 +82,7 @@ module Gitlab
description
=
@formatter
.
author_line
(
pull_request
.
author
)
description
+=
pull_request
.
description
project
.
merge_requests
.
create
(
merge_request
=
project
.
merge_requests
.
create
(
iid:
pull_request
.
iid
,
title:
pull_request
.
title
,
description:
description
,
...
...
@@ -98,11 +98,79 @@ module Gitlab
created_at:
pull_request
.
created_at
,
updated_at:
pull_request
.
updated_at
)
import_pull_request_comments
(
pull_request
,
merge_request
)
if
merge_request
.
persisted?
rescue
ActiveRecord
::
RecordInvalid
nil
end
end
end
def
import_pull_request_comments
(
pull_request
,
merge_request
)
comments
=
client
.
pull_request_comments
(
repo
,
pull_request
.
iid
)
inline_comments
,
pr_comments
=
comments
.
partition
(
&
:inline?
)
import_inline_comments
(
inline_comments
,
pull_request
,
merge_request
)
import_standalone_pr_comments
(
pr_comments
,
merge_request
)
end
def
import_inline_comments
(
inline_comments
,
pull_request
,
merge_request
)
line_code_map
=
{}
children
,
parents
=
inline_comments
.
partition
(
&
:has_parent?
)
# The Bitbucket API returns threaded replies as parent-child
# relationships. We assume that the child can appear in any order in
# the JSON.
parents
.
each
do
|
comment
|
line_code_map
[
comment
.
iid
]
=
generate_line_code
(
comment
)
end
children
.
each
do
|
comment
|
line_code_map
[
comment
.
iid
]
=
line_code_map
.
fetch
(
comment
.
parent_id
,
nil
)
end
inline_comments
.
each
do
|
comment
|
begin
attributes
=
pull_request_comment_attributes
(
comment
)
attributes
.
merge!
(
commit_id:
pull_request
.
source_branch_sha
,
line_code:
line_code_map
.
fetch
(
comment
.
iid
),
type:
'LegacyDiffNote'
)
note
=
merge_request
.
notes
.
create!
(
attributes
)
rescue
ActiveRecord
::
RecordInvalid
=>
e
Rails
.
log
.
error
(
"Bitbucket importer ERROR: Invalid pull request comment
#{
e
.
message
}
"
)
nil
end
end
end
def
import_standalone_pr_comments
(
pr_comments
,
merge_request
)
pr_comments
.
each
do
|
comment
|
begin
merge_request
.
notes
.
create!
(
pull_request_comment_attributes
(
comment
))
rescue
ActiveRecord
::
RecordInvalid
=>
e
Rails
.
log
.
error
(
"Bitbucket importer ERROR: Invalid standalone pull request comment
#{
e
.
message
}
"
)
nil
end
end
end
def
generate_line_code
(
pr_comment
)
Gitlab
::
Diff
::
LineCode
.
generate
(
pr_comment
.
file_path
,
pr_comment
.
new_pos
,
pr_comment
.
old_pos
)
end
def
pull_request_comment_attributes
(
comment
)
{
project:
project
,
note:
comment
.
note
,
author_id:
gitlab_user_id
(
project
,
comment
.
author
),
created_at:
comment
.
created_at
,
updated_at:
comment
.
updated_at
}
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