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

changed_label.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: 6c408158b0234f8f7abe2c12ba988b310134555d (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
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Importer
      module Events
        class ChangedLabel
          def initialize(project, user_id)
            @project = project
            @user_id = user_id
          end

          # issue_event - An instance of `Gitlab::GithubImport::Representation::IssueEvent`.
          def execute(issue_event)
            create_event(issue_event)
          end

          private

          attr_reader :project, :user_id

          def create_event(issue_event)
            ResourceLabelEvent.create!(
              issue_id: issue_event.issue_db_id,
              user_id: user_id,
              label_id: label_finder.id_for(issue_event.label_title),
              action: action(issue_event.event),
              created_at: issue_event.created_at
            )
          end

          def label_finder
            Gitlab::GithubImport::LabelFinder.new(project)
          end

          def action(event_type)
            event_type == 'unlabeled' ? 'remove' : 'add'
          end
        end
      end
    end
  end
end