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
014abc9c
Commit
014abc9c
authored
Jun 28, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle threaded comments and prepare for inline comments
parent
5728ffbf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
45 deletions
+118
-45
lib/bitbucket_server/representation/activity.rb
lib/bitbucket_server/representation/activity.rb
+13
-17
lib/bitbucket_server/representation/comment.rb
lib/bitbucket_server/representation/comment.rb
+61
-8
lib/bitbucket_server/representation/pull_request_comment.rb
lib/bitbucket_server/representation/pull_request_comment.rb
+38
-17
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+6
-3
No files found.
lib/bitbucket_server/representation/activity.rb
View file @
014abc9c
...
@@ -13,31 +13,27 @@ module BitbucketServer
...
@@ -13,31 +13,27 @@ module BitbucketServer
comment?
&&
raw
[
'commentAnchor'
]
comment?
&&
raw
[
'commentAnchor'
]
end
end
def
id
def
comment
raw
[
'id'
]
return
unless
comment?
end
def
note
comment
[
'text'
]
end
def
author_username
author
[
'name'
]
end
def
author_email
@comment
||=
author
[
'emailAddress'
]
if
inline_comment?
PullRequestComment
.
new
(
raw_comment
)
else
Comment
.
new
(
raw_comment
)
end
end
end
# XXX Move this into MergeEvent
def
merge_event?
def
merge_event?
action
==
'MERGED'
action
==
'MERGED'
end
end
def
commiter_user
def
commit
t
er_user
commit
.
fetch
(
'committer'
,
{})[
'displayName'
]
commit
.
fetch
(
'committer'
,
{})[
'displayName'
]
end
end
def
commiter_email
def
commit
t
er_email
commit
.
fetch
(
'committer'
,
{})[
'emailAddress'
]
commit
.
fetch
(
'committer'
,
{})[
'emailAddress'
]
end
end
...
@@ -61,12 +57,12 @@ module BitbucketServer
...
@@ -61,12 +57,12 @@ module BitbucketServer
private
private
def
comment
def
raw_
comment
raw
.
fetch
(
'comment'
,
{})
raw
.
fetch
(
'comment'
,
{})
end
end
def
author
def
author
comment
.
fetch
(
'author'
,
{})
raw_
comment
.
fetch
(
'author'
,
{})
end
end
# Anchor hash:
# Anchor hash:
...
...
lib/bitbucket_server/representation/comment.rb
View file @
014abc9c
module
Bitbucket
module
Bitbucket
Server
module
Representation
module
Representation
# A general comment with the structure:
# "comment": {
# "author": {
# "active": true,
# "displayName": "root",
# "emailAddress": "stanhu+bitbucket@gitlab.com",
# "id": 1,
# "links": {
# "self": [
# {
# "href": "http://localhost:7990/users/root"
# }
# ]
# },
# "name": "root",
# "slug": "root",
# "type": "NORMAL"
# }
# }
# }
class
Comment
<
Representation
::
Base
class
Comment
<
Representation
::
Base
def
author
def
id
user
[
'username'
]
raw
[
'id'
]
end
def
author_username
author
[
'username'
]
end
def
author_email
author
[
'displayName'
]
end
end
def
note
def
note
raw
.
fetch
(
'content'
,
{}).
fetch
(
'raw'
,
nil
)
raw
[
'text'
]
end
end
def
created_at
def
created_at
raw
[
'created_on'
]
Time
.
at
(
created_date
/
1000
)
if
created_date
.
is_a?
(
Integer
)
end
end
def
updated_at
def
updated_at
raw
[
'updated_on'
]
||
raw
[
'created_on'
]
Time
.
at
(
updated_date
/
1000
)
if
created_date
.
is_a?
(
Integer
)
end
def
comments
workset
=
[
raw
[
'comments'
]].
compact
all_comments
=
[]
until
workset
.
empty?
comments
=
workset
.
pop
comments
.
each
do
|
comment
|
new_comments
=
comment
.
delete
(
'comments'
)
workset
<<
new_comments
if
new_comments
all_comments
<<
Comment
.
new
(
comment
)
end
end
all_comments
end
end
private
private
def
user
def
author
raw
.
fetch
(
'user'
,
{})
raw
.
fetch
(
'author'
,
{})
end
def
created_date
raw
[
'createdDate'
]
end
def
updated_date
raw
[
'updatedDate'
]
end
end
end
end
end
end
...
...
lib/bitbucket_server/representation/pull_request_comment.rb
View file @
014abc9c
module
Bitbucket
module
Bitbucket
Server
module
Representation
module
Representation
# An inline comment with the following structure that identifies
# the part of the diff:
#
# "commentAnchor": {
# "diffType": "EFFECTIVE",
# "fileType": "TO",
# "fromHash": "c5f4288162e2e6218180779c7f6ac1735bb56eab",
# "line": 1,
# "lineType": "ADDED",
# "orphaned": false,
# "path": "CHANGELOG.md",
# "toHash": "a4c2164330f2549f67c13f36a93884cf66e976be"
# }
class
PullRequestComment
<
Comment
class
PullRequestComment
<
Comment
def
iid
def
file_type
raw
[
'id
'
]
comment_anchor
[
'fileType
'
]
end
end
def
f
ile_path
def
f
rom_sha
inline
.
fetch
(
'path'
)
comment_anchor
[
'fromHash'
]
end
end
def
old_pos
def
to_sha
inline
.
fetch
(
'from'
)
comment_anchor
[
'toHash'
]
end
end
def
new_pos
def
to?
inline
.
fetch
(
'to'
)
file_type
==
'TO'
end
def
from?
file_type
==
'FROM'
end
end
def
parent_id
def
new_pos
raw
.
fetch
(
'parent'
,
{}).
fetch
(
'id'
,
nil
)
return
unless
to?
comment_anchor
[
'line'
]
end
end
def
inline?
def
old_pos
raw
.
key?
(
'inline'
)
return
unless
from?
comment_anchor
[
'line'
]
end
end
def
has_parent?
def
file_path
raw
.
key?
(
'parent
'
)
comment_anchor
.
fetch
(
'path
'
)
end
end
private
private
def
inline
def
comment_anchor
raw
.
fetch
(
'
inline
'
,
{})
raw
.
fetch
(
'
commentAnchor
'
,
{})
end
end
end
end
end
end
...
...
lib/gitlab/bitbucket_server_import/importer.rb
View file @
014abc9c
...
@@ -105,11 +105,11 @@ module Gitlab
...
@@ -105,11 +105,11 @@ module Gitlab
inline_comments
,
pr_comments
=
comments
.
partition
(
&
:inline_comment?
)
inline_comments
,
pr_comments
=
comments
.
partition
(
&
:inline_comment?
)
# import_inline_comments(inline_comments, pull_request, merge_request)
# import_inline_comments(inline_comments, pull_request, merge_request)
import_standalone_pr_comments
(
pr_comments
,
merge_request
)
import_standalone_pr_comments
(
pr_comments
.
map
(
&
:comment
)
,
merge_request
)
end
end
def
import_merge_event
(
merge_request
,
merge_event
)
def
import_merge_event
(
merge_request
,
merge_event
)
committer
=
merge_event
.
commiter_email
committer
=
merge_event
.
commit
t
er_email
return
unless
committer
return
unless
committer
...
@@ -169,6 +169,10 @@ module Gitlab
...
@@ -169,6 +169,10 @@ module Gitlab
pr_comments
.
each
do
|
comment
|
pr_comments
.
each
do
|
comment
|
begin
begin
merge_request
.
notes
.
create!
(
pull_request_comment_attributes
(
comment
))
merge_request
.
notes
.
create!
(
pull_request_comment_attributes
(
comment
))
comment
.
comments
.
each
do
|
replies
|
merge_request
.
notes
.
create!
(
pull_request_comment_attributes
(
replies
))
end
rescue
StandardError
=>
e
rescue
StandardError
=>
e
errors
<<
{
type: :pull_request
,
iid:
comment
.
id
,
errors:
e
.
message
}
errors
<<
{
type: :pull_request
,
iid:
comment
.
id
,
errors:
e
.
message
}
end
end
...
@@ -180,7 +184,6 @@ module Gitlab
...
@@ -180,7 +184,6 @@ module Gitlab
end
end
def
pull_request_comment_attributes
(
comment
)
def
pull_request_comment_attributes
(
comment
)
byebug
{
{
project:
project
,
project:
project
,
note:
comment
.
note
,
note:
comment
.
note
,
...
...
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