diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-03-27 11:43:03 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-03 15:50:22 -0300 |
commit | 336ba94a7bbdd52f07d0f1c7f7bced20c37ad307 (patch) | |
tree | 881862060ce559f579ac8d5b31f1b81844678eea /app/services | |
parent | 97c49b8426c62b5b398ed9a2bf863d859a4b7e55 (diff) | |
download | gitlab-ce-336ba94a7bbdd52f07d0f1c7f7bced20c37ad307.tar.gz |
Fetch GitHub project as a mirror to get all refs at once
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/import_service.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/app/services/projects/import_service.rb b/app/services/projects/import_service.rb index d484a96f785..794cc1556a4 100644 --- a/app/services/projects/import_service.rb +++ b/app/services/projects/import_service.rb @@ -21,7 +21,11 @@ module Projects # In this case, we only want to import issues, not a repository. create_repository elsif !project.repository_exists? - import_repository + if project.github_import? || project.gitea_import? + fetch_repository + else + import_repository + end end end @@ -45,6 +49,25 @@ module Projects end end + def fetch_repository + begin + raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url) + + project.create_repository + project.repository.add_remote(project.import_type, project.import_url) + project.repository.set_remote_as_mirror (project.import_type) + project.repository.fetch_remote(project.import_type, forced: true) + project.repository.remove_remote(project.import_type) + rescue => e + # Expire cache to prevent scenarios such as: + # 1. First import failed, but the repo was imported successfully, so +exists?+ returns true + # 2. Retried import, repo is broken or not imported but +exists?+ still returns true + project.repository.before_import if project.repository_exists? + + raise Error, "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}" + end + end + def import_data return unless has_importer? |