summaryrefslogtreecommitdiff
path: root/lib/github/representation
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-12 22:42:12 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commit2c92cc52d74d41663e96a0a3eabf268db3f68947 (patch)
treeb4c9c84304e0dcd3781aa1a5163f7448e1483250 /lib/github/representation
parent0b1d1931fb00f15987f695d76efb5dac9d3992d7 (diff)
downloadgitlab-ce-2c92cc52d74d41663e96a0a3eabf268db3f68947.tar.gz
Add comment representation
Diffstat (limited to 'lib/github/representation')
-rw-r--r--lib/github/representation/comment.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/github/representation/comment.rb b/lib/github/representation/comment.rb
new file mode 100644
index 00000000000..ac7832ce28b
--- /dev/null
+++ b/lib/github/representation/comment.rb
@@ -0,0 +1,58 @@
+module Github
+ module Representation
+ class Comment < Representation::Base
+ def note
+ raw['body'] || ''
+ end
+
+ def author
+ @author ||= Github::Representation::User.new(raw['user'])
+ 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
+
+ def type
+ 'LegacyDiffNote' if on_diff?
+ end
+
+ def url
+ raw['url']
+ end
+
+ def created_at
+ raw['created_at']
+ end
+
+ def updated_at
+ raw['updated_at']
+ 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
+ raw_data.diff_hunk
+ end
+
+ def file_path
+ raw_data.path
+ end
+ end
+ end
+end