summaryrefslogtreecommitdiff
path: root/lib/gitlab/legacy_github_import/issuable_formatter.rb
blob: 1a0aefbbd6266ce8597f5c1a9491d539bd08221a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

module Gitlab
  module LegacyGithubImport
    class IssuableFormatter < BaseFormatter
      attr_writer :assignee_id, :author_id

      def project_association
        raise NotImplementedError
      end

      delegate :number, to: :raw_data

      def find_condition
        { iid: number }
      end

      private

      def state
        raw_data.state == 'closed' ? 'closed' : 'opened'
      end

      def assigned?
        raw_data.assignee.present?
      end

      def author
        @author ||= UserFormatter.new(client, raw_data.user)
      end

      def author_id
        @author_id ||= author.gitlab_id || project.creator_id
      end

      def assignee
        if assigned?
          @assignee ||= UserFormatter.new(client, raw_data.assignee)
        end
      end

      def assignee_id
        return @assignee_id if defined?(@assignee_id)

        @assignee_id = assignee.try(:gitlab_id)
      end

      def body
        raw_data.body || ""
      end

      def description
        if author.gitlab_id
          body
        else
          formatter.author_line(author.login) + body
        end
      end

      # rubocop: disable CodeReuse/ActiveRecord
      def milestone
        if raw_data.milestone.present?
          milestone = MilestoneFormatter.new(project, raw_data.milestone)
          project.milestones.find_by(milestone.find_condition)
        end
      end
      # rubocop: enable CodeReuse/ActiveRecord
    end
  end
end