2015-12-23 12:04:46 -05:00
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
2015-12-23 17:02:59 -05:00
|
|
|
class CommentFormatter < BaseFormatter
|
2017-02-03 10:07:22 -05:00
|
|
|
attr_writer :author_id
|
|
|
|
|
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,
|
2016-06-06 11:19:03 -04:00
|
|
|
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
|
2017-02-03 10:07:22 -05:00
|
|
|
@author ||= UserFormatter.new(client, raw_data.user)
|
2015-12-23 12:04:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def author_id
|
2017-02-03 10:07:22 -05:00
|
|
|
author.gitlab_id || project.creator_id
|
2015-12-23 12:04:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
|
|
|
raw_data.body || ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def line_code
|
2016-05-03 01:45:46 -04:00
|
|
|
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)
|
2017-10-10 13:44:14 -04:00
|
|
|
Gitlab::Git.diff_line_code(file_path, line.new_pos, line.old_pos)
|
2015-12-23 12:04:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_diff?
|
2016-05-03 01:45:46 -04:00
|
|
|
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
|
2017-02-03 10:07:22 -05:00
|
|
|
if author.gitlab_id
|
2016-08-29 05:48:36 -04:00
|
|
|
body
|
|
|
|
else
|
2017-02-03 10:07:22 -05:00
|
|
|
formatter.author_line(author.login) + body
|
2016-08-29 05:48:36 -04:00
|
|
|
end
|
2015-12-23 12:04:46 -05:00
|
|
|
end
|
2016-06-06 11:19:03 -04:00
|
|
|
|
|
|
|
def type
|
|
|
|
'LegacyDiffNote' if on_diff?
|
|
|
|
end
|
2015-12-23 12:04:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|