Commit Graph

158 Commits

Author SHA1 Message Date
Takuya Noguchi 2b6307f6ad Enable RuboCop Style/RegexpLiteral 2018-02-01 02:06:07 +09:00
Jacob Vosmaer 6d6f7536bd Look for rugged with static analysis 2018-01-25 14:05:11 +01:00
Lin Jen-Shin 4f00a05152 Introduce PredicateMemoization cop and fix offenses
with StrongMemoize
2018-01-12 17:54:55 +08:00
Zeger-Jan van de Weg 338f1eaf35
Migrate to Project#empty_repo? 2017-12-20 19:13:11 +01:00
Douwe Maan 7a1e93d35b Rename fetch_refs to refmap 2017-11-23 16:59:58 +01:00
Douwe Maan 0e6beaf50c Clean up repository fetch and mirror methods 2017-11-23 16:59:50 +01:00
Douwe Maan 8da236611b Prefer polymorphism over specific type checks in Import service 2017-11-15 13:40:35 +01:00
Yorick Peterse f37fe2edc8
Support importing GH projects without rate limits
GitHub Enterprise disables rate limiting for the API, resulting in HTTP
404 errors when requesting rate limiting details. This changes
Gitlab::GithubImport::Client so it can deal with rate limiting being
disabled.
2017-11-08 21:37:01 +01:00
Yorick Peterse 2b886a7815
Restore Enterprise support in the GH importer
This was removed by accident as the old GitHub importer handled this
deep down the codebase, making it easy to miss.
2017-11-08 18:06:03 +01:00
Yorick Peterse 4dfe26cd8b
Rewrite the GitHub importer from scratch
Prior to this MR there were two GitHub related importers:

* Github::Import: the main importer used for GitHub projects
* Gitlab::GithubImport: importer that's somewhat confusingly used for
  importing Gitea projects (apparently they have a compatible API)

This MR renames the Gitea importer to Gitlab::LegacyGithubImport and
introduces a new GitHub importer in the Gitlab::GithubImport namespace.
This new GitHub importer uses Sidekiq for importing multiple resources
in parallel, though it also has the ability to import data sequentially
should this be necessary.

The new code is spread across the following directories:

* lib/gitlab/github_import: this directory contains most of the importer
  code such as the classes used for importing resources.
* app/workers/gitlab/github_import: this directory contains the Sidekiq
  workers, most of which simply use the code from the directory above.
* app/workers/concerns/gitlab/github_import: this directory provides a
  few modules that are included in every GitHub importer worker.

== Stages

The import work is divided into separate stages, with each stage
importing a specific set of data. Stages will schedule the work that
needs to be performed, followed by scheduling a job for the
"AdvanceStageWorker" worker. This worker will periodically check if all
work is completed and schedule the next stage if this is the case. If
work is not yet completed this worker will reschedule itself.

Using this approach we don't have to block threads by calling `sleep()`,
as doing so for large projects could block the thread from doing any
work for many hours.

== Retrying Work

Workers will reschedule themselves whenever necessary. For example,
hitting the GitHub API's rate limit will result in jobs rescheduling
themselves. These jobs are not processed until the rate limit has been
reset.

== User Lookups

Part of the importing process involves looking up user details in the
GitHub API so we can map them to GitLab users. The old importer used
an in-memory cache, but this obviously doesn't work when the work is
spread across different threads.

The new importer uses a Redis cache and makes sure we only perform
API/database calls if absolutely necessary.  Frequently used keys are
refreshed, and lookup misses are also cached; removing the need for
performing API/database calls if we know we don't have the data we're
looking for.

== Performance & Models

The new importer in various places uses raw INSERT statements (as
generated by `Gitlab::Database.bulk_insert`) instead of using Rails
models. This allows us to bypass any validations and callbacks,
drastically reducing the number of SQL queries and Gitaly RPC calls
necessary to import projects.

To ensure the code produces valid data the corresponding tests check if
the produced rows are valid according to the model validation rules.
2017-11-07 23:24:59 +01:00
Nick Thomas 314e5b5f20
Use wiki.disk_path 2017-10-18 12:53:06 +01:00
Alejandro Rodríguez 9fdde3693b Move line code generation into Gitlab::Git
Having a distinct class just for that was a bit overkill
2017-10-12 22:13:05 -03:00
Alejandro Rodríguez faa9bd402d Create a Gitlab::Git submodule for conlict-related files
Rename classes to (hopefully) clearer names while we're doing that.
2017-10-12 22:03:15 -03:00
Alejandro Rodríguez f72598b659 Move Gitlab::Diff::LineCode to module Gitlab::Git 2017-10-12 21:45:16 -03:00
Ahmad Sherif 41ef94e777 Migrate creating/deleting a branch to Gitaly 2017-09-06 17:25:17 +02:00
Robert Speicher 260c8da060 Whitelist or fix additional `Gitlab/PublicSend` cop violations
An upcoming update to rubocop-gitlab-security added additional
violations.
2017-08-14 12:14:11 -04:00
Gabriel Mazetto fb06a4d8fe Rename more path_with_namespace -> full_path or disk_path 2017-08-01 07:28:13 +02:00
Gabriel Mazetto abb878326c Rename many path_with_namespace -> full_path 2017-08-01 07:26:58 +02:00
Valery Sizov 387c4b2c21 Backport of multiple_assignees_feature [ci skip] 2017-05-04 17:11:53 +03:00
Douglas Barbosa Alexandre a6affc66dc Rename skip_metrics to imported on the importable concern 2017-04-03 15:50:22 -03:00
Douglas Barbosa Alexandre 20486593bd Skip MR metrics when importing projects from GitHub 2017-04-03 15:50:22 -03:00
Douglas Barbosa Alexandre 336ba94a7b Fetch GitHub project as a mirror to get all refs at once 2017-04-03 15:50:22 -03:00
Gabriel Mazetto 3c75ee2823 Minor refactor 2017-04-03 12:45:31 +02:00
Douglas Barbosa Alexandre c8273ba858 Fix BrachFormatter for removed users 2017-04-03 12:45:31 +02:00
Gabriel Mazetto 291bd873d3 One more change to the branch names to preserve metadata 2017-04-03 12:45:31 +02:00
Douglas Barbosa Alexandre 59588ebac0 Prefixes source branch name with short SHA to avoid collision 2017-04-03 12:45:31 +02:00
Gabriel Mazetto a3e65ef021 Fix GitHub importer for PRs of deleted forked repositories 2017-04-03 12:45:31 +02:00
Gabriel Mazetto a996880bf7 Using guard clause and added more specs 2017-03-10 21:13:45 +01:00
Gabriel Mazetto 9b53cb6c88 Fix GitHub Import for open PRs from a fork 2017-03-10 21:08:21 +01:00
Gabriel Mazetto ce35dcbc81 Refactor some code 2017-03-08 19:42:21 +01:00
Gabriel Mazetto 26fa716dd2 Fix name colision when importing GitHub pull requests from forked repositories 2017-03-08 19:42:21 +01:00
Douglas Barbosa Alexandre ec4b03a4c6 Fix 'Object not found - no match for id (sha)' when importing GitHub PRs 2017-03-07 15:59:07 -03:00
Douwe Maan 56de781a2c Revert "Enable Style/DotPosition"
This reverts commit e00fb2bdc2090e9cabeb1eb35a2672a882cc96e9.

# Conflicts:
#	.rubocop.yml
#	.rubocop_todo.yml
#	lib/gitlab/ci/config/entry/global.rb
#	lib/gitlab/ci/config/entry/jobs.rb
#	spec/lib/gitlab/ci/config/entry/factory_spec.rb
#	spec/lib/gitlab/ci/config/entry/global_spec.rb
#	spec/lib/gitlab/ci/config/entry/job_spec.rb
#	spec/lib/gitlab/ci/status/build/factory_spec.rb
#	spec/lib/gitlab/incoming_email_spec.rb
2017-02-23 09:33:19 -06:00
Douwe Maan 1fe7501b49 Revert "Prefer leading style for Style/DotPosition"
This reverts commit cb10b725c8929b8b4460f89c9d96c773af39ba6b.
2017-02-23 09:33:05 -06:00
Douwe Maan 75f5fa997d Enable Rails/Delegate 2017-02-23 09:32:42 -06:00
Douwe Maan 206953a430 Prefer leading style for Style/DotPosition 2017-02-23 09:32:22 -06:00
Douwe Maan 030baf70d2 Enable Performance/RedundantMerge 2017-02-23 09:31:57 -06:00
Douwe Maan 3dadf306dd Enable Style/DotPosition 2017-02-23 09:31:56 -06:00
Douglas Barbosa Alexandre 43b1f5e40d Reuse User#find_by_any_email on UserFormatter#find_by_email 2017-02-20 14:48:12 -03:00
Douglas Barbosa Alexandre 20128693eb Use leading periods on UserFormatter#find_by_external_uid 2017-02-20 14:48:12 -03:00
Douglas Barbosa Alexandre 7da13fee84 Add a simple cache for Gitlab::GithubImport::Client#user 2017-02-20 14:48:12 -03:00
Douglas Barbosa Alexandre 2d1e0a0811 GitHub Importer - Find users based on their email address
The returned email by the GitHub API is the user's publicly visible
email address (or null if the user has not specified a public email
address in their profile)
2017-02-20 14:48:12 -03:00
Robert Speicher 414d695db7 Merge branch 'fix-github-import-MR-wrong-project' into 'security'
Fix labels being applied to wrong merge requests on GitHub import

See https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2064
2017-02-15 10:42:56 -05:00
Grzegorz Bizon 632c2939bb Revert "Merge branch 'revert-9cac0317' into 'master' "
This reverts commit c20934869f, reversing
changes made to 4b7ec44b91.
2017-01-23 16:35:24 +01:00
Grzegorz Bizon baeaa97ef4 Revert "Merge branch 'dont-persist-application-settings-in-test-env' into 'master'"
This reverts merge request !8573
2017-01-21 22:55:35 +00:00
Rémy Coutable f6cc29ed83 Don't persist ApplicationSetting in test env
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-01-15 01:07:29 -05:00
Rémy Coutable ab06313c36 Add Project#gitea_import?
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-19 17:35:51 +01:00
Rémy Coutable 99ddd1dcbe Modify GithubImport to support Gitea
The reason is that Gitea plan to be GitHub-compatible so it makes sense
to just modify GitHubImport a bit for now, and hopefully we can change
it to GitHubishImport once Gitea is 100%-compatible.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-19 17:35:51 +01:00
Kim "BKC" Carlbäcker 5d4531db25 Gogs Importer 2016-12-19 17:35:51 +01:00
Douglas Barbosa Alexandre 8ca040d8ae Fix branch validation for GitHub PR where repo/fork was renamed/deleted 2016-12-01 00:03:12 -02:00