Class: Gitlab::BareRepositoryImport::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/bare_repository_import/importer.rb

Constant Summary collapse

NoAdminError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, bare_repo) ⇒ Importer

Returns a new instance of Importer.


45
46
47
48
# File 'lib/gitlab/bare_repository_import/importer.rb', line 45

def initialize(user, bare_repo)
  @user = user
  @bare_repo = bare_repo
end

Instance Attribute Details

#bare_repoObject (readonly)

Returns the value of attribute bare_repo


40
41
42
# File 'lib/gitlab/bare_repository_import/importer.rb', line 40

def bare_repo
  @bare_repo
end

#project_nameObject (readonly)

Returns the value of attribute project_name


40
41
42
# File 'lib/gitlab/bare_repository_import/importer.rb', line 40

def project_name
  @project_name
end

#userObject (readonly)

Returns the value of attribute user


40
41
42
# File 'lib/gitlab/bare_repository_import/importer.rb', line 40

def user
  @user
end

Class Method Details

.execute(import_path) ⇒ Object


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
# File 'lib/gitlab/bare_repository_import/importer.rb', line 8

def self.execute(import_path)
  unless import_path.ends_with?('/')
    import_path = "#{import_path}/"
  end

  repos_to_import = Dir.glob(import_path + '**/*.git')

  unless user = User.admins.order_id_asc.first
    raise NoAdminError.new('No admin user found to import repositories')
  end

  repos_to_import.each do |repo_path|
    bare_repo = Gitlab::BareRepositoryImport::Repository.new(import_path, repo_path)

    unless bare_repo.processable?
      log " * Skipping repo #{bare_repo.repo_path}".color(:yellow)

      next
    end

    log "Processing #{repo_path}".color(:yellow)

    new(user, bare_repo).create_project_if_needed
  end
end

.log(message) ⇒ Object

This is called from within a rake task only used by Admins, so allow writing to STDOUT


36
37
38
# File 'lib/gitlab/bare_repository_import/importer.rb', line 36

def self.log(message)
  puts message # rubocop:disable Rails/Output
end

Instance Method Details

#create_project_if_neededObject


50
51
52
53
54
55
56
57
58
# File 'lib/gitlab/bare_repository_import/importer.rb', line 50

def create_project_if_needed
  if project = Project.find_by_full_path(project_full_path)
    log " * #{project.name} (#{project_full_path}) exists"

    return project
  end

  create_project
end