1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
# frozen_string_literal: true
module BitbucketServer
module Representation
class Activity < Representation::Base
def id
raw['id']
end
def comment?
action == 'COMMENTED'
end
def inline_comment?
!!(comment? && comment_anchor)
end
def comment
return unless comment?
@comment ||=
if inline_comment?
PullRequestComment.new(raw)
else
Comment.new(raw)
end
end
# TODO Move this into MergeEvent
def merge_event?
action == 'MERGED'
end
def committer_user
commit.dig('committer', 'displayName')
end
def committer_name
commit.dig('committer', 'displayName')
end
def committer_username
commit.dig('committer', 'slug')
end
def committer_email
commit.dig('committer', 'emailAddress')
end
def merge_timestamp
timestamp = commit['committerTimestamp']
self.class.convert_timestamp(timestamp)
end
def merge_commit
commit['id']
end
def approved_event?
action == 'APPROVED'
end
def approver_name
raw.dig('user', 'displayName')
end
def approver_username
raw.dig('user', 'slug')
end
def approver_email
raw.dig('user', 'emailAddress')
end
def declined_event?
action == 'DECLINED'
end
def decliner_name
raw.dig('user', 'displayName')
end
def decliner_username
raw.dig('user', 'slug')
end
def decliner_email
raw.dig('user', 'emailAddress')
end
def created_at
self.class.convert_timestamp(created_date)
end
def to_hash
{
id: id,
committer_name: committer_user,
committer_user: committer_user,
committer_username: committer_username,
committer_email: committer_email,
merge_timestamp: merge_timestamp,
merge_commit: merge_commit,
approver_name: approver_name,
approver_username: approver_username,
approver_email: approver_email,
decliner_name: decliner_name,
decliner_username: decliner_username,
decliner_email: decliner_email,
created_at: created_at
}
end
private
def commit
raw.fetch('commit', {})
end
def action
raw['action']
end
def comment_anchor
raw['commentAnchor']
end
def created_date
raw['createdDate']
end
end
end
end
|