Class: Gitlab::LegacyGithubImport::Importer
- Inherits:
-
Object
- Object
- Gitlab::LegacyGithubImport::Importer
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/legacy_github_import/importer.rb
Constant Summary collapse
- PLACEHOLDER_LOAD_SLEEP =
3- PLACEHOLDER_LOAD_TIMEOUT =
300
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#repo_url ⇒ Object
readonly
Returns the value of attribute repo_url.
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #execute ⇒ Object
-
#initialize(project) ⇒ Importer
constructor
A new instance of Importer.
- #source_user_mapper ⇒ Object
Constructor Details
#initialize(project) ⇒ Importer
Returns a new instance of Importer.
17 18 19 20 21 22 23 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 17 def initialize(project) @project = project @repo = project.import_source @repo_url = project.unsafe_import_url @errors = [] @labels = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 15 def errors @errors end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
15 16 17 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 15 def project @project end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
15 16 17 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 15 def repo @repo end |
#repo_url ⇒ Object (readonly)
Returns the value of attribute repo_url.
15 16 17 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 15 def repo_url @repo_url end |
Class Method Details
.refmap ⇒ Object
11 12 13 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 11 def self.refmap Gitlab::GithubImport.refmap end |
Instance Method Details
#client ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 25 def 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.unsafe_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 |
#execute ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 55 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? wait_for_placeholder_references handle_errors true end |
#source_user_mapper ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/gitlab/legacy_github_import/importer.rb', line 46 def source_user_mapper Gitlab::Import::SourceUserMapper.new( namespace: project.root_ancestor, import_type: project.import_type, source_hostname: client.host ) end |