Welcome to mirror list, hosted at ThFree Co, Russian Federation.

changed_assignee.rb « events « importer « github_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c8f6335e4a81e25ffb67c2f5ffb9f91ec1ee4ba7 (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
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Importer
      module Events
        class ChangedAssignee < BaseImporter
          def execute(issue_event)
            assignee_id = author_id(issue_event, author_key: :assignee)
            assigner_id = author_id(issue_event, author_key: :assigner)

            note_body = parse_body(issue_event, assigner_id, assignee_id)

            create_note(issue_event, note_body, assigner_id)
          end

          private

          def create_note(issue_event, note_body, assigner_id)
            Note.create!(
              system: true,
              noteable_type: Issue.name,
              noteable_id: issuable_db_id(issue_event),
              project: project,
              author_id: assigner_id,
              note: note_body,
              system_note_metadata: SystemNoteMetadata.new(
                {
                  action: "assignee",
                  created_at: issue_event.created_at,
                  updated_at: issue_event.created_at
                }
              ),
              created_at: issue_event.created_at,
              updated_at: issue_event.created_at
            )
          end

          def parse_body(issue_event, assigner_id, assignee_id)
            Gitlab::I18n.with_default_locale do
              if issue_event.event == "unassigned"
                "unassigned #{User.find(assigner_id).to_reference}"
              else
                "assigned to #{User.find(assignee_id).to_reference}"
              end
            end
          end
        end
      end
    end
  end
end