Read about our upcoming Code of Conduct on this issue

stage_methods.rb 981 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module StageMethods
      # project_id - The ID of the GitLab project to import the data into.
      def perform(project_id)
        return unless (project = find_project(project_id))

        client = GithubImport.new_client_for(project)

        try_import(client, project)
      end

      # client - An instance of Gitlab::GithubImport::Client.
      # project - An instance of Project.
      def try_import(client, project)
        import(client, project)
      rescue RateLimitError
        self.class.perform_in(client.rate_limit_resets_in, project.id)
      end

23
      # rubocop: disable CodeReuse/ActiveRecord
24
25
26
      def find_project(id)
        # If the project has been marked as failed we want to bail out
        # automatically.
27
        Project.joins_import_state.where(import_state: { status: :started }).find_by(id: id)
28
      end
29
      # rubocop: enable CodeReuse/ActiveRecord
30
31
32
    end
  end
end