summaryrefslogtreecommitdiff
path: root/lib/gitlab/phabricator_import/issues/task_importer.rb
blob: 40d4392cbc119a5d62707d3d1b52fd739112b6c3 (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
# frozen_string_literal: true
module Gitlab
  module PhabricatorImport
    module Issues
      class TaskImporter
        def initialize(project, task)
          @project, @task = project, task
        end

        def execute
          # TODO: get the user from the project namespace from the username loaded by Phab-id
          # https://gitlab.com/gitlab-org/gitlab-ce/issues/60565
          issue.author = User.ghost

          # TODO: Reformat the description with attachments, escaping accidental
          # links and add attachments
          # https://gitlab.com/gitlab-org/gitlab-ce/issues/60603
          issue.assign_attributes(task.issue_attributes)

          save!

          issue
        end

        private

        attr_reader :project, :task

        def save!
          # Just avoiding an extra redis call, we've already updated the expiry
          # when reading the id from the map
          was_persisted = issue.persisted?

          issue.save! if issue.changed?

          object_map.set_gitlab_model(issue, task.phabricator_id) unless was_persisted
        end

        def issue
          @issue ||= find_issue_by_phabricator_id(task.phabricator_id) ||
            project.issues.new
        end

        def find_issue_by_phabricator_id(phabricator_id)
          object_map.get_gitlab_model(phabricator_id)
        end

        def object_map
          Gitlab::PhabricatorImport::Cache::Map.new(project)
        end
      end
    end
  end
end