File: project_import_status.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (38 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download
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
# frozen_string_literal: true

module API
  module Entities
    class ProjectImportStatus < ProjectIdentity
      expose :import_status, documentation: { type: 'string', example: 'scheduled' }
      expose :import_type, documentation: { type: 'string', example: 'gitlab_project' }
      expose :correlation_id, documentation: {
        type: 'string', example: 'dfcf583058ed4508e4c7c617bd7f0edd'
      } do |project, _options|
        project.import_state&.correlation_id
      end

      expose :failed_relations, using: Entities::ProjectImportFailedRelation, documentation: {
        is_array: true
      } do |project, _options|
        project.import_state&.relation_hard_failures(limit: 100) || []
      end

      expose :import_error, documentation: { type: 'string', example: 'Error message' } do |project, options|
        next unless options[:current_user]
        next unless project.import_state&.last_error

        if Ability.allowed?(options[:current_user], :read_import_error, project)
          project.import_state&.last_error
        else
          _("Ask a maintainer to check the import status for more details.")
        end
      end

      expose :stats, documentation: { type: 'object' } do |project, _options|
        if project.github_import?
          ::Gitlab::GithubImport::ObjectCounter.summary(project)
        end
      end
    end
  end
end