Class: BitbucketServer::Representation::Comment

Inherits:
Base
  • Object
show all
Defined in:
lib/bitbucket_server/representation/comment.rb

Overview

A general comment with the structure: “comment”: {

"author": {
            "active": true,
            "displayName": "root",
            "emailAddress": "[email protected]",
            "id": 1,
            "links": {
              "self": [
                {
                  "href": "http://localhost:7990/users/root"
                }
              ]
             },
             "name": "root",
             "slug": "root",
             "type": "NORMAL"
            }
}

}

Direct Known Subclasses

PullRequestComment

Defined Under Namespace

Classes: CommentNode

Instance Attribute Summary collapse

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

convert_timestamp, decorate

Constructor Details

#initialize(raw, parent_comment: nil) ⇒ Comment

Returns a new instance of Comment.



30
31
32
33
34
# File 'lib/bitbucket_server/representation/comment.rb', line 30

def initialize(raw, parent_comment: nil)
  super(raw)

  @parent_comment = parent_comment
end

Instance Attribute Details

#parent_commentObject (readonly)

Returns the value of attribute parent_comment.



26
27
28
# File 'lib/bitbucket_server/representation/comment.rb', line 26

def parent_comment
  @parent_comment
end

Instance Method Details

#author_emailObject



46
47
48
# File 'lib/bitbucket_server/representation/comment.rb', line 46

def author_email
  author['emailAddress']
end

#author_usernameObject



40
41
42
43
44
# File 'lib/bitbucket_server/representation/comment.rb', line 40

def author_username
  author['username'] ||
    author['slug'] ||
    author['displayName']
end

#commentsObject

Bitbucket Server supports the ability to reply to any comment and created multiple threads. It represents these as a linked list of comments within comments. For example:

“comments”: [

{
   "author" : ...
   "comments": [
      {
         "author": ...

Since GitLab only supports a single thread, we flatten all these comments into a single discussion.



75
76
77
# File 'lib/bitbucket_server/representation/comment.rb', line 75

def comments
  @comments ||= flatten_comments
end

#created_atObject



54
55
56
# File 'lib/bitbucket_server/representation/comment.rb', line 54

def created_at
  self.class.convert_timestamp(created_date)
end

#idObject



36
37
38
# File 'lib/bitbucket_server/representation/comment.rb', line 36

def id
  raw_comment['id']
end

#noteObject



50
51
52
# File 'lib/bitbucket_server/representation/comment.rb', line 50

def note
  raw_comment['text']
end

#updated_atObject



58
59
60
# File 'lib/bitbucket_server/representation/comment.rb', line 58

def updated_at
  self.class.convert_timestamp(created_date)
end