Class: Gitlab::GithubImport::Importer::RepositoryImporter

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/github_import/importer/repository_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, client) ⇒ RepositoryImporter

Returns a new instance of RepositoryImporter.



11
12
13
14
15
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 11

def initialize(project, client)
  @project = project
  @client = client
  @wiki_formatter = ::Gitlab::LegacyGithubImport::WikiFormatter.new(project)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 9

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project.



9
10
11
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 9

def project
  @project
end

#wiki_formatterObject (readonly)

Returns the value of attribute wiki_formatter.



9
10
11
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 9

def wiki_formatter
  @wiki_formatter
end

Instance Method Details

#executeObject

Imports the repository data.

This method will return true if the data was imported successfully or the repository had already been imported before.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 30

def execute
  imported =
    # It's possible a repository has already been imported when running
    # this code, e.g. because we had to retry this job after
    # `import_wiki?` raised a rate limit error. In this case we'll skip
    # re-importing the main repository.
    if project.empty_repo?
      import_repository
    else
      true
    end

  update_clone_time if imported

  imported = import_wiki_repository if import_wiki? && imported

  imported
end

#import_repositoryObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 49

def import_repository
  project.ensure_repository

  refmap = Gitlab::GithubImport.refmap
  project.repository.fetch_as_mirror(project.import_url, refmap: refmap, forced: true)

  project.change_head(default_branch) if default_branch

  validate_repository_size!

  # The initial fetch can bring in lots of loose refs and objects.
  # Running a `git gc` will make importing pull requests faster.
  Repositories::HousekeepingService.new(project, :gc).execute

  true
end

#import_wiki?Boolean

Returns true if we should import the wiki for the project. rubocop: disable CodeReuse/ActiveRecord

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 19

def import_wiki?
  client_repository[:has_wiki] &&
    !project.wiki_repository_exists? &&
    Gitlab::GitalyClient::RemoteService.exists?(wiki_url)
end

#import_wiki_repositoryObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 66

def import_wiki_repository
  project.wiki.repository.import_repository(wiki_formatter.import_url)

  true
rescue ::Gitlab::Git::CommandError => e
  return true if e.message.include?('repository not exported')

  project.create_wiki
  raise e
end

#update_clone_timeObject



81
82
83
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 81

def update_clone_time
  project.touch(:last_repository_updated_at)
end

#wiki_urlObject



77
78
79
# File 'lib/gitlab/github_import/importer/repository_importer.rb', line 77

def wiki_url
  wiki_formatter.import_url
end