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

changed_milestone.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: 39b92d88b58514dd577fee6804d695fd18b1152b (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
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Importer
      module Events
        class ChangedMilestone < BaseImporter
          # GitHub API doesn't provide the historical state of an issue for
          # de/milestoned issue events. So we'll assign the default state to
          # those events that are imported from GitHub.
          DEFAULT_STATE = Issue.available_states[:opened]

          def execute(issue_event)
            create_event(issue_event)
          end

          private

          def create_event(issue_event)
            attrs = {
              user_id: author_id(issue_event),
              created_at: issue_event.created_at,
              milestone_id: project.milestones.find_by_title(issue_event.milestone_title)&.id,
              action: action(issue_event.event),
              state: DEFAULT_STATE
            }.merge(resource_event_belongs_to(issue_event))

            ResourceMilestoneEvent.create!(attrs)
          end

          def action(event_type)
            return ResourceMilestoneEvent.actions[:remove] if event_type == 'demilestoned'

            ResourceMilestoneEvent.actions[:add]
          end
        end
      end
    end
  end
end