BigW Consortium Gitlab

issuable_formatter.rb 1.33 KB
Newer Older
1 2 3
module Gitlab
  module GithubImport
    class IssuableFormatter < BaseFormatter
4 5
      attr_writer :assignee_id, :author_id

6 7 8 9
      def project_association
        raise NotImplementedError
      end

Douwe Maan committed
10
      delegate :number, to: :raw_data
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

      def find_condition
        { iid: number }
      end

      private

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

      def assigned?
        raw_data.assignee.present?
      end

26 27 28 29 30 31 32 33 34
      def author
        @author ||= UserFormatter.new(client, raw_data.user)
      end

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

      def assignee
35
        if assigned?
36
          @assignee ||= UserFormatter.new(client, raw_data.assignee)
37 38 39
        end
      end

40 41
      def assignee_id
        return @assignee_id if defined?(@assignee_id)
42

43
        @assignee_id = assignee.try(:gitlab_id)
44 45 46 47 48 49 50
      end

      def body
        raw_data.body || ""
      end

      def description
51
        if author.gitlab_id
52 53
          body
        else
54
          formatter.author_line(author.login) + body
55 56 57 58 59 60 61 62 63 64 65 66
        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