2016-01-14 18:37:52 +05:30
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class CommentFormatter < BaseFormatter
|
2017-08-17 22:00:37 +05:30
|
|
|
attr_writer :author_id
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
def attributes
|
|
|
|
{
|
|
|
|
project: project,
|
|
|
|
note: note,
|
|
|
|
commit_id: raw_data.commit_id,
|
|
|
|
line_code: line_code,
|
|
|
|
author_id: author_id,
|
2016-06-16 23:09:34 +05:30
|
|
|
type: type,
|
2016-01-14 18:37:52 +05:30
|
|
|
created_at: raw_data.created_at,
|
|
|
|
updated_at: raw_data.updated_at
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def author
|
2017-08-17 22:00:37 +05:30
|
|
|
@author ||= UserFormatter.new(client, raw_data.user)
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def author_id
|
2017-08-17 22:00:37 +05:30
|
|
|
author.gitlab_id || project.creator_id
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
|
|
|
raw_data.body || ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def line_code
|
2016-06-02 11:05:42 +05:30
|
|
|
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)
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def on_diff?
|
2016-06-02 11:05:42 +05:30
|
|
|
diff_hunk.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def diff_hunk
|
|
|
|
raw_data.diff_hunk
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_path
|
|
|
|
raw_data.path
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def note
|
2017-08-17 22:00:37 +05:30
|
|
|
if author.gitlab_id
|
2016-09-29 09:46:39 +05:30
|
|
|
body
|
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
formatter.author_line(author.login) + body
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
def type
|
|
|
|
'LegacyDiffNote' if on_diff?
|
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|