Files
gitlabhq/lib/gitlab/github_import/comment_formatter.rb
Douwe MaanandYorick Peterse 4f9d82a9e3 Merge branch 'gh-review-comments' into 'master'
Fix the line code when importing PR review comments from GitHub

Pull Request Review Comments are comments on a portion of the unified diff.

Closes #17205

See merge request !4010
2016-05-05 19:35:54 +02:00

59 lines
1.1 KiB
Ruby

module Gitlab
module GithubImport
class CommentFormatter < BaseFormatter
def attributes
{
project: project,
note: note,
commit_id: raw_data.commit_id,
line_code: line_code,
author_id: author_id,
created_at: raw_data.created_at,
updated_at: raw_data.updated_at
}
end
private
def author
raw_data.user.login
end
def author_id
gl_user_id(raw_data.user.id) || project.creator_id
end
def body
raw_data.body || ""
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 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
def note
formatter.author_line(author) + body
end
end
end
end