summaryrefslogtreecommitdiff
path: root/lib/bitbucket_server
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-06-28 00:27:04 -0700
committerStan Hu <stanhu@gmail.com>2018-06-28 00:27:04 -0700
commit014abc9c07c1389e64ccf336559b488835730a45 (patch)
tree94f44ff09f543fe5c349dd07bc9659150d384b54 /lib/bitbucket_server
parent5728ffbf12c8f5f767bc6d6b9a453b2add974e96 (diff)
downloadgitlab-ce-014abc9c07c1389e64ccf336559b488835730a45.tar.gz
Handle threaded comments and prepare for inline comments
Diffstat (limited to 'lib/bitbucket_server')
-rw-r--r--lib/bitbucket_server/representation/activity.rb30
-rw-r--r--lib/bitbucket_server/representation/comment.rb69
-rw-r--r--lib/bitbucket_server/representation/pull_request_comment.rb55
3 files changed, 112 insertions, 42 deletions
diff --git a/lib/bitbucket_server/representation/activity.rb b/lib/bitbucket_server/representation/activity.rb
index 207bc848b28..aa168aca8af 100644
--- a/lib/bitbucket_server/representation/activity.rb
+++ b/lib/bitbucket_server/representation/activity.rb
@@ -13,31 +13,27 @@ module BitbucketServer
comment? && raw['commentAnchor']
end
- def id
- raw['id']
- end
-
- def note
- comment['text']
- end
-
- def author_username
- author['name']
- end
+ def comment
+ return unless comment?
- def author_email
- author['emailAddress']
+ @comment ||=
+ if inline_comment?
+ PullRequestComment.new(raw_comment)
+ else
+ Comment.new(raw_comment)
+ end
end
+ # XXX Move this into MergeEvent
def merge_event?
action == 'MERGED'
end
- def commiter_user
+ def committer_user
commit.fetch('committer', {})['displayName']
end
- def commiter_email
+ def committer_email
commit.fetch('committer', {})['emailAddress']
end
@@ -61,12 +57,12 @@ module BitbucketServer
private
- def comment
+ def raw_comment
raw.fetch('comment', {})
end
def author
- comment.fetch('author', {})
+ raw_comment.fetch('author', {})
end
# Anchor hash:
diff --git a/lib/bitbucket_server/representation/comment.rb b/lib/bitbucket_server/representation/comment.rb
index 4937aa9728f..bd6f9f08e3c 100644
--- a/lib/bitbucket_server/representation/comment.rb
+++ b/lib/bitbucket_server/representation/comment.rb
@@ -1,26 +1,79 @@
-module Bitbucket
+module BitbucketServer
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
- def author
- user['username']
+ def id
+ raw['id']
+ end
+
+ def author_username
+ author['username']
+ end
+
+ def author_email
+ author['displayName']
end
def note
- raw.fetch('content', {}).fetch('raw', nil)
+ raw['text']
end
def created_at
- raw['created_on']
+ Time.at(created_date / 1000) if created_date.is_a?(Integer)
end
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
private
- def user
- raw.fetch('user', {})
+ def author
+ raw.fetch('author', {})
+ end
+
+ def created_date
+ raw['createdDate']
+ end
+
+ def updated_date
+ raw['updatedDate']
end
end
end
diff --git a/lib/bitbucket_server/representation/pull_request_comment.rb b/lib/bitbucket_server/representation/pull_request_comment.rb
index c52acbc3ddc..a04c120b0b0 100644
--- a/lib/bitbucket_server/representation/pull_request_comment.rb
+++ b/lib/bitbucket_server/representation/pull_request_comment.rb
@@ -1,38 +1,59 @@
-module Bitbucket
+module BitbucketServer
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
- def iid
- raw['id']
+ def file_type
+ comment_anchor['fileType']
end
- def file_path
- inline.fetch('path')
+ def from_sha
+ comment_anchor['fromHash']
end
- def old_pos
- inline.fetch('from')
+ def to_sha
+ comment_anchor['toHash']
end
- def new_pos
- inline.fetch('to')
+ def to?
+ file_type == 'TO'
+ end
+
+ def from?
+ file_type == 'FROM'
end
- def parent_id
- raw.fetch('parent', {}).fetch('id', nil)
+ def new_pos
+ return unless to?
+
+ comment_anchor['line']
end
- def inline?
- raw.key?('inline')
+ def old_pos
+ return unless from?
+
+ comment_anchor['line']
end
- def has_parent?
- raw.key?('parent')
+ def file_path
+ comment_anchor.fetch('path')
end
private
- def inline
- raw.fetch('inline', {})
+ def comment_anchor
+ raw.fetch('commentAnchor', {})
end
end
end