2016-12-15 11:36:53 -05:00
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class IssuableFormatter < BaseFormatter
|
2017-02-03 10:07:22 -05:00
|
|
|
attr_writer :assignee_id, :author_id
|
|
|
|
|
2016-12-15 11:36:53 -05:00
|
|
|
def project_association
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2017-02-22 12:51:46 -05:00
|
|
|
delegate :number, to: :raw_data
|
2016-12-15 11:36:53 -05:00
|
|
|
|
|
|
|
def find_condition
|
|
|
|
{ iid: number }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def state
|
|
|
|
raw_data.state == 'closed' ? 'closed' : 'opened'
|
|
|
|
end
|
|
|
|
|
|
|
|
def assigned?
|
|
|
|
raw_data.assignee.present?
|
|
|
|
end
|
|
|
|
|
2017-02-03 10:07:22 -05:00
|
|
|
def author
|
|
|
|
@author ||= UserFormatter.new(client, raw_data.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_id
|
|
|
|
@author_id ||= author.gitlab_id || project.creator_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def assignee
|
2016-12-15 11:36:53 -05:00
|
|
|
if assigned?
|
2017-02-03 10:07:22 -05:00
|
|
|
@assignee ||= UserFormatter.new(client, raw_data.assignee)
|
2016-12-15 11:36:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-03 10:07:22 -05:00
|
|
|
def assignee_id
|
|
|
|
return @assignee_id if defined?(@assignee_id)
|
2016-12-15 11:36:53 -05:00
|
|
|
|
2017-02-03 10:07:22 -05:00
|
|
|
@assignee_id = assignee.try(:gitlab_id)
|
2016-12-15 11:36:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
|
|
|
raw_data.body || ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2017-02-03 10:07:22 -05:00
|
|
|
if author.gitlab_id
|
2016-12-15 11:36:53 -05:00
|
|
|
body
|
|
|
|
else
|
2017-02-03 10:07:22 -05:00
|
|
|
formatter.author_line(author.login) + body
|
2016-12-15 11:36:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def milestone
|
|
|
|
if raw_data.milestone.present?
|
|
|
|
milestone = MilestoneFormatter.new(project, raw_data.milestone)
|
|
|
|
project.milestones.find_by(milestone.find_condition)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|