summaryrefslogtreecommitdiff
path: root/lib/bitbucket_server/representation/activity.rb
blob: 2e6082bea87ec79e7deb4918d4fc846173102a6c (plain)
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
# frozen_string_literal: true

module BitbucketServer
  module Representation
    class Activity < Representation::Base
      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
        raw.dig('commit', 'committer', 'displayName')
      end

      def committer_email
        raw.dig('commit', 'committer', 'emailAddress')
      end

      def merge_timestamp
        timestamp = raw.dig('commit', 'committerTimestamp')

        Time.at(timestamp / 1000.0) if timestamp.is_a?(Integer)
      end

      def created_at
        Time.at(created_date / 1000) if created_date.is_a?(Integer)
      end

      private

      def action
        raw['action']
      end

      def comment_anchor
        raw['commentAnchor']
      end

      def created_date
        raw['createdDate']
      end
    end
  end
end