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
930b5e7a
Commit
930b5e7a
authored
Jul 25, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for pull request comments and add comments
parent
d09034ac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
4 deletions
+76
-4
lib/bitbucket_server/representation/pull_request_comment.rb
lib/bitbucket_server/representation/pull_request_comment.rb
+28
-4
spec/lib/bitbucket_server/representation/pull_request_comment_spec.rb
...bucket_server/representation/pull_request_comment_spec.rb
+48
-0
No files found.
lib/bitbucket_server/representation/pull_request_comment.rb
View file @
930b5e7a
...
@@ -15,11 +15,9 @@ module BitbucketServer
...
@@ -15,11 +15,9 @@ module BitbucketServer
# "path": "CHANGELOG.md",
# "path": "CHANGELOG.md",
# "toHash": "a4c2164330f2549f67c13f36a93884cf66e976be"
# "toHash": "a4c2164330f2549f67c13f36a93884cf66e976be"
# }
# }
#
# More details in https://docs.atlassian.com/bitbucket-server/rest/5.12.0/bitbucket-rest.html.
class
PullRequestComment
<
Comment
class
PullRequestComment
<
Comment
def
file_type
comment_anchor
[
'fileType'
]
end
def
from_sha
def
from_sha
comment_anchor
[
'fromHash'
]
comment_anchor
[
'fromHash'
]
end
end
...
@@ -44,6 +42,12 @@ module BitbucketServer
...
@@ -44,6 +42,12 @@ module BitbucketServer
line_type
==
'REMOVED'
line_type
==
'REMOVED'
end
end
# There are three line comment types: added, removed, or context.
#
# 1. An added type means a new line was inserted, so there is no old position.
# 2. A removed type means a line was removed, so there is no new position.
# 3. A context type means the line was unmodified, so there is both a
# old and new position.
def
new_pos
def
new_pos
return
if
removed?
return
if
removed?
return
unless
line_position
return
unless
line_position
...
@@ -64,10 +68,30 @@ module BitbucketServer
...
@@ -64,10 +68,30 @@ module BitbucketServer
private
private
def
file_type
comment_anchor
[
'fileType'
]
end
def
line_type
def
line_type
comment_anchor
[
'lineType'
]
comment_anchor
[
'lineType'
]
end
end
# Each comment contains the following information about the diff:
#
# hunks: [
# {
# segments: [
# {
# "lines": [
# {
# "commentIds": [ N ],
# "source": X,
# "destination": Y
# }, ...
# ] ....
#
# To determine the line position of a comment, we search all the lines
# entries until we find this comment ID.
def
line_position
def
line_position
@line_position
||=
diff_hunks
.
each
do
|
hunk
|
@line_position
||=
diff_hunks
.
each
do
|
hunk
|
segments
=
hunk
.
fetch
(
'segments'
,
[])
segments
=
hunk
.
fetch
(
'segments'
,
[])
...
...
spec/lib/bitbucket_server/representation/pull_request_comment_spec.rb
0 → 100644
View file @
930b5e7a
require
'spec_helper'
describe
BitbucketServer
::
Representation
::
PullRequestComment
do
let
(
:activities
)
{
JSON
.
parse
(
fixture_file
(
'importers/bitbucket_server/activities.json'
))[
'values'
]
}
let
(
:comment
)
{
activities
.
second
}
subject
{
described_class
.
new
(
comment
)
}
describe
'#id'
do
it
{
expect
(
subject
.
id
).
to
eq
(
7
)
}
end
describe
'#from_sha'
do
it
{
expect
(
subject
.
from_sha
).
to
eq
(
'c5f4288162e2e6218180779c7f6ac1735bb56eab'
)
}
end
describe
'#to_sha'
do
it
{
expect
(
subject
.
to_sha
).
to
eq
(
'a4c2164330f2549f67c13f36a93884cf66e976be'
)
}
end
describe
'#to?'
do
it
{
expect
(
subject
.
to?
).
to
be_falsey
}
end
describe
'#from?'
do
it
{
expect
(
subject
.
from?
).
to
be_truthy
}
end
describe
'#added?'
do
it
{
expect
(
subject
.
added?
).
to
be_falsey
}
end
describe
'#removed?'
do
it
{
expect
(
subject
.
removed?
).
to
be_falsey
}
end
describe
'#new_pos'
do
it
{
expect
(
subject
.
new_pos
).
to
eq
(
11
)
}
end
describe
'#old_pos'
do
it
{
expect
(
subject
.
old_pos
).
to
eq
(
9
)
}
end
describe
'#file_path'
do
it
{
expect
(
subject
.
file_path
).
to
eq
(
'CHANGELOG.md'
)
}
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