Class: Gitlab::LegacyGithubImport::Importer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Importer

Returns a new instance of Importer.



12
13
14
15
16
17
18
# File 'lib/gitlab/legacy_github_import/importer.rb', line 12

def initialize(project)
  @project  = project
  @repo     = project.import_source
  @repo_url = project.import_url
  @errors   = []
  @labels   = {}
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'lib/gitlab/legacy_github_import/importer.rb', line 10

def errors
  @errors
end

#projectObject (readonly)

Returns the value of attribute project.



10
11
12
# File 'lib/gitlab/legacy_github_import/importer.rb', line 10

def project
  @project
end

#repoObject (readonly)

Returns the value of attribute repo.



10
11
12
# File 'lib/gitlab/legacy_github_import/importer.rb', line 10

def repo
  @repo
end

#repo_urlObject (readonly)

Returns the value of attribute repo_url.



10
11
12
# File 'lib/gitlab/legacy_github_import/importer.rb', line 10

def repo_url
  @repo_url
end

Class Method Details

.refmapObject



6
7
8
# File 'lib/gitlab/legacy_github_import/importer.rb', line 6

def self.refmap
  Gitlab::GithubImport.refmap
end

Instance Method Details

#clientObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/legacy_github_import/importer.rb', line 20

def client
  return @client if defined?(@client)

  unless credentials
    raise Projects::ImportService::Error,
      "Unable to find project import data credentials for project ID: #{@project.id}"
  end

  opts = {}
  # Gitea plan to be GitHub compliant
  if project.gitea_import?
    uri = URI.parse(project.import_url)
    host = "#{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}".sub(%r{/?[\w-]+/[\w-]+\.git\z}, '')
    opts = {
      host: host,
      api_version: 'v1'
    }
  end

  @client = Client.new(credentials[:user], **opts)
end

#executeObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gitlab/legacy_github_import/importer.rb', line 42

def execute
  # The ordering of importing is important here due to the way GitHub structures their data
  # 1. Labels are required by other items while not having a dependency on anything else
  # so need to be first
  # 2. Pull requests must come before issues. Every pull request is also an issue but not
  # all issues are pull requests. Only the issue entity has labels defined in GitHub. GitLab
  # doesn't structure data like this so we need to make sure that we've created the MRs
  # before we attempt to add the labels defined in the GitHub issue for the related, already
  # imported, pull request
  import_labels
  import_milestones
  import_pull_requests
  import_issues
  import_comments(:issues)

  # Gitea doesn't have an API endpoint for pull requests comments
  import_comments(:pull_requests) unless project.gitea_import?

  import_wiki

  # Gitea doesn't have a Release API yet
  # See https://github.com/go-gitea/gitea/issues/330
  # On re-enabling care should be taken to include releases `author_id` field and enable corresponding tests.
  # See:
  # 1) https://gitlab.com/gitlab-org/gitlab/-/issues/343448#note_985979730
  # 2) https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89694/diffs#dfc4a8141aa296465ea3c50b095a30292fb6ebc4_180_182
  import_releases unless project.gitea_import?

  handle_errors

  true
end