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
710d8210
Commit
710d8210
authored
Jul 31, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track parental relationships in comments
parent
89d164fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
7 deletions
+55
-7
lib/bitbucket_server/representation/comment.rb
lib/bitbucket_server/representation/comment.rb
+38
-7
spec/lib/bitbucket_server/representation/comment_spec.rb
spec/lib/bitbucket_server/representation/comment_spec.rb
+17
-0
No files found.
lib/bitbucket_server/representation/comment.rb
View file @
710d8210
...
@@ -23,6 +23,16 @@ module BitbucketServer
...
@@ -23,6 +23,16 @@ module BitbucketServer
# }
# }
# }
# }
class
Comment
<
Representation
::
Base
class
Comment
<
Representation
::
Base
attr_reader
:parent_comment
CommentNode
=
Struct
.
new
(
:raw_comments
,
:parent
)
def
initialize
(
raw
,
parent_comment:
nil
)
super
(
raw
)
@parent_comment
=
parent_comment
end
def
id
def
id
raw_comment
[
'id'
]
raw_comment
[
'id'
]
end
end
...
@@ -61,24 +71,45 @@ module BitbucketServer
...
@@ -61,24 +71,45 @@ module BitbucketServer
# Since GitLab only supports a single thread, we flatten all these
# Since GitLab only supports a single thread, we flatten all these
# comments into a single discussion.
# comments into a single discussion.
def
comments
def
comments
workset
=
[
raw_comment
[
'comments'
]].
compact
@comments
||=
flatten_comments
end
private
# In order to provide context for each reply, we need to track
# the parent of each comment. This method works as follows:
#
# 1. Insert the root comment into the workset. The root element is the current note.
# 2. For each node in the workset:
# a. Examine if it has replies to that comment. If it does,
# insert that node into the workset.
# b. Parse that note into a Comment structure and add it to a flat list.
def
flatten_comments
comments
=
raw_comment
[
'comments'
]
workset
=
if
comments
[
CommentNode
.
new
(
comments
,
self
)]
else
[]
end
all_comments
=
[]
all_comments
=
[]
until
workset
.
empty?
until
workset
.
empty?
comments
=
workset
.
pop
node
=
workset
.
pop
parent
=
node
.
parent
comments
.
each
do
|
comment
|
node
.
raw_
comments
.
each
do
|
comment
|
new_comments
=
comment
.
delete
(
'comments'
)
new_comments
=
comment
.
delete
(
'comments'
)
workset
<<
new_comments
if
new_comments
current_comment
=
Comment
.
new
({
'comment'
=>
comment
},
parent_comment:
parent
)
all_comments
<<
Comment
.
new
({
'comment'
=>
comment
})
all_comments
<<
current_comment
workset
<<
CommentNode
.
new
(
new_comments
,
current_comment
)
if
new_comments
end
end
end
end
all_comments
all_comments
end
end
private
def
raw_comment
def
raw_comment
raw
.
fetch
(
'comment'
,
{})
raw
.
fetch
(
'comment'
,
{})
end
end
...
...
spec/lib/bitbucket_server/representation/comment_spec.rb
View file @
710d8210
...
@@ -34,5 +34,22 @@ describe BitbucketServer::Representation::Comment do
...
@@ -34,5 +34,22 @@ describe BitbucketServer::Representation::Comment do
it
{
expect
(
subject
.
comments
.
count
).
to
eq
(
4
)
}
it
{
expect
(
subject
.
comments
.
count
).
to
eq
(
4
)
}
it
{
expect
(
subject
.
comments
).
to
all
(
be_a
(
described_class
)
)
}
it
{
expect
(
subject
.
comments
).
to
all
(
be_a
(
described_class
)
)
}
it
{
expect
(
subject
.
comments
.
map
(
&
:note
)).
to
match_array
([
"Hello world"
,
"Ok"
,
"hello"
,
"hi"
])
}
it
{
expect
(
subject
.
comments
.
map
(
&
:note
)).
to
match_array
([
"Hello world"
,
"Ok"
,
"hello"
,
"hi"
])
}
# The thread should look like:
#
# is this a new line? (subject)
# -> Hello world (first)
# -> Ok (third)
# -> Hi (fourth)
# -> hello (second)
it
'comments have the right parent'
do
first
,
second
,
third
,
fourth
=
subject
.
comments
[
0
..
4
]
expect
(
subject
.
parent_comment
).
to
be_nil
expect
(
first
.
parent_comment
).
to
eq
(
subject
)
expect
(
second
.
parent_comment
).
to
eq
(
subject
)
expect
(
third
.
parent_comment
).
to
eq
(
first
)
expect
(
fourth
.
parent_comment
).
to
eq
(
first
)
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