BigW Consortium Gitlab

comment.rb 796 Bytes
Newer Older
1 2 3 4 5 6 7 8
module Github
  module Representation
    class Comment < Representation::Base
      def note
        raw['body'] || ''
      end

      def author
9
        @author ||= Github::Representation::User.new(raw['user'], options)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
      end

      def commit_id
        raw['commit_id']
      end

      def line_code
        return unless on_diff?

        parsed_lines = Gitlab::Diff::Parser.new.parse(diff_hunk.lines)
        generate_line_code(parsed_lines.to_a.last)
      end

      private

      def generate_line_code(line)
        Gitlab::Diff::LineCode.generate(file_path, line.new_pos, line.old_pos)
      end

      def on_diff?
        diff_hunk.present?
      end

      def diff_hunk
34
        raw['diff_hunk']
35 36 37
      end

      def file_path
38
        raw['path']
39 40 41 42
      end
    end
  end
end