gitlab-org--gitlab-foss/lib/gitlab/github_import/comment_formatter.rb

68 lines
1.3 KiB
Ruby
Raw Normal View History

2015-12-23 12:04:46 -05:00
module Gitlab
module GithubImport
class CommentFormatter < BaseFormatter
2015-12-23 12:04:46 -05:00
def attributes
{
project: project,
note: note,
commit_id: raw_data.commit_id,
line_code: line_code,
author_id: author_id,
type: type,
2015-12-23 12:04:46 -05:00
created_at: raw_data.created_at,
updated_at: raw_data.updated_at
}
end
private
def author
raw_data.user.login
end
def author_id
gitlab_author_id || project.creator_id
2015-12-23 12:04:46 -05:00
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)
2015-12-23 12:04:46 -05:00
end
def on_diff?
diff_hunk.present?
end
def diff_hunk
raw_data.diff_hunk
end
def file_path
raw_data.path
2015-12-23 12:04:46 -05:00
end
def note
if gitlab_author_id
body
else
formatter.author_line(author) + body
end
2015-12-23 12:04:46 -05:00
end
def type
'LegacyDiffNote' if on_diff?
end
2015-12-23 12:04:46 -05:00
end
end
end