summaryrefslogtreecommitdiff
path: root/lib/github/representation/comment.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-26 11:34:21 +0000
committerLin Jen-Shin <godfat@godfat.org>2017-04-28 17:40:26 +0800
commitf886c6f7e66e356fc48d845df2ac62e2a3b0ed00 (patch)
treef8f510167c2d632fbe9073ba34cb13ab206d4b89 /lib/github/representation/comment.rb
parentf243fa79938e46e8fca5ecb05980e7e52f35adc3 (diff)
downloadgitlab-ce-f886c6f7e66e356fc48d845df2ac62e2a3b0ed00.tar.gz
Merge branch 'fix/github-importer' into 'master'
Refactoring rake task to import GitHub repositories See merge request !10695
Diffstat (limited to 'lib/github/representation/comment.rb')
-rw-r--r--lib/github/representation/comment.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/github/representation/comment.rb b/lib/github/representation/comment.rb
new file mode 100644
index 00000000000..1b5be91461b
--- /dev/null
+++ b/lib/github/representation/comment.rb
@@ -0,0 +1,42 @@
+module Github
+ module Representation
+ class Comment < Representation::Base
+ def note
+ raw['body'] || ''
+ end
+
+ def author
+ @author ||= Github::Representation::User.new(raw['user'], options)
+ 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
+ raw['diff_hunk']
+ end
+
+ def file_path
+ raw['path']
+ end
+ end
+ end
+end