Commit Graph

72 Commits

Author SHA1 Message Date
George Koltsov 4e64ca4477 Add BitbucketServerController filtering spec 2019-08-12 11:16:17 +01:00
Heinrich Lee Yu 1ce5bcacdb Remove code related to object hierarchy in MySQL
These are not required because MySQL is not
supported anymore
2019-07-25 15:35:06 +08:00
Matija Čupić 1f40372029
Do not authorize with OAuth for CICD only projects 2019-07-23 11:48:23 +02:00
Stan Hu 1a4d1b0501 Fix Fogbugz Importer not working
This stopped working in GitLab 11.11 when we upgraded to Rails 5.1.
Rails 5 changed ActionController::Parameters to return an Object instead
of a Hash. The old behavior was deprecated in Rails 5 but finally
removed in Rails 5.1

Since the controller wasn't updated properly, the callback endpoint
quietly failed with the message, "Could not connect to FogBugz, check
your url".

To fix this, we need to call `to_h` on the `import_params` to access the
Hash. We also need to do this for the user map and permit specific keys.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/33530
2019-06-09 23:53:49 -07:00
Bob Van Landuyt 589b2db06c Setup Phabricator import
This sets up all the basics for importing Phabricator tasks into
GitLab issues.

To import all tasks from a Phabricator instance into GitLab, we'll
import all of them into a new project that will have its repository
disabled.

The import is hooked into a regular ProjectImport setup, but similar
to the GitHub parallel importer takes care of all the imports itself.

In this iteration, we're importing each page of tasks in a separate
sidekiq job.

The first thing we do when requesting a new page of tasks is schedule
the next page to be imported. But to avoid deadlocks, we only allow a
single job per worker type to run at the same time.

For now we're only importing basic Issue information, this should be
extended to richer information.
2019-05-31 09:40:54 +02:00
gfyoung 93a44e135b Add some frozen string to spec/**/*.rb
Adds frozen string to the following:

* spec/bin/**/*.rb
* spec/config/**/*.rb
* spec/controllers/**/*.rb

xref https://gitlab.com/gitlab-org/gitlab-ce/issues/59758
2019-04-15 10:17:05 +00:00
Luke Bennett 534a61179e
Improve the GitHub and Gitea import feature table interface
These are backend changes.
Use Vue for the import feature UI for "githubish"
providers (GitHub and Gitea).
Add "Go to project" button after a successful import.
Use CI-style status icons and improve spacing of the
table and its component.
Adds ETag polling to the github and gitea import
jobs endpoint.
2019-02-13 00:15:57 +00:00
Stan Hu 88f2e9615c
Alias GitHub and BitBucket OAuth2 callback URLs
To prevent an OAuth2 covert redirect vulnerability, this commit adds and
uses an alias for the GitHub and BitBucket OAuth2 callback URLs to the
following paths:

GitHub: /users/auth/-/import/github
Bitbucket: /users/auth/-/import/bitbucket

This allows admins to put a more restrictive callback URL in the OAuth2
configuration settings. Instead of https://example.com, admins can now use:

https://example.com/users/auth

It's possible but not trivial to change Devise and OmniAuth to use a
different prefix for callback URLs instead of /users/auth. For now,
aliasing the import URLs under the /users/auth namespace should suffice.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/56663
2019-01-31 16:52:48 +01:00
Stan Hu eafccaad73 Fix Bitbucket Server import not allowing personal projects
Bitbucket Server places personal projects in a namespace called
`~username`. This change allows those projects and also strips
them from the GitLab namespace.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53419
2019-01-28 13:06:27 -08:00
Stan Hu 660dcd5b7c Fix Bitbucket Server importer error handling
The importer would display a 500 error page if you attempted to import
using a non-existent DNS entry. This commit rescues known network issues
and consolidates them into
BitbucketServer::Connection::ConnectionError`.  The previous error
handling in the paginator doesn't work because it returns a lazy
collection.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/56154
2019-01-12 22:14:08 -08:00
blackst0ne b44a2c801a Update specs to rails5 format
Updates specs to use new rails5 format.

The old format:
`get :show, { some: params }, { some: headers }`

The new format:
`get :show, params: { some: params }, headers: { some: headers }`
2018-12-19 10:04:31 +11:00
Stan Hu b4e2679437 Allow GitHub imports via token even if OAuth2 provider not configured
Previously, the GitHub importer would only work if the site configured
an OAuth2 provider were configured. Users attempting to import via a
GitHub personal access token would see an Error 500 due to a failed
redirection. We fix this by only doing the redirection if the provider
has been configured and allowing users to see the new import page.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/38524
2018-12-10 11:56:14 -08:00
Tiago Botelho 4bd8a427d4
Removes all the irrelevant import related code and columns
Clears the import related columns and code from the Project
model over to the ProjectImportState model
2018-11-27 12:58:13 +00:00
Stan Hu 5b6d5301d9 Paginate Bitbucket Server importer projects
To prevent delays in loading the page and reduce memory usage, limit the
number of projects shown at 25 per page.

Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/50021
2018-11-07 11:37:46 -08:00
James Lopez e72aeccdae Resolve "Unable to import repository: undefined method `import_file' for nil:NilClass" 2018-09-17 10:52:49 +00:00
Stan Hu 3f715bb438 Consolidate server errors and add specs 2018-07-26 23:05:22 -07:00
Stan Hu 079b490ad2 Fix failing specs 2018-07-26 21:55:23 -07:00
Stan Hu 6a992fb4c5 Add missing stubbed parameter 2018-07-17 21:07:00 -07:00
Stan Hu 0936bff496 Finish specs for spec/controllers/import/bitbucket_server_controller_spec.rb 2018-07-09 16:04:41 -07:00
Stan Hu 589a28889a Test server connection error 2018-07-08 14:57:30 -07:00
Stan Hu ed166b791f Add spec when project can't be saved 2018-07-08 14:49:09 -07:00
Stan Hu 4c5085f68d Add spec for project not found 2018-07-08 07:49:47 -07:00
Stan Hu 5d7e130e64 Add more specs and fix some typos 2018-07-08 07:44:33 -07:00
Stan Hu 24ac81cca6 Add initial specs for app/controllers/import/bitbucket_server_controller.rb 2018-07-08 07:38:07 -07:00
Robert Speicher 6d165c740c Make all uses of `fixture_file_upload` use relative paths 2018-06-07 09:54:41 -05:00
Lin Jen-Shin ab286656b2 Resolve "Namespace factory is problematic" 2018-04-23 15:48:26 +00:00
James Lopez 68e31c098e Merge branch 'fix/gh-namespace-issue' into 'security-10-4'
[10.4] Fix GH namespace security issue
2018-02-09 12:16:28 -06:00
Clement Ho 71c948d637 Replace $.post in importer status with axios 2018-02-09 11:14:48 +00:00
Stan Hu 1f96512ba1 Merge branch 'sh-validate-path-project-import-10-3' into 'security-10-3'
Validate project path in Gitlab import - 10.3 port

See merge request gitlab/gitlabhq!2268

(cherry picked from commit 94c82376d66fc80d46dd2d5eeb5bade408ec6a7e)

2b94a7c2 Validate project path in Gitlab import
2018-01-16 17:04:38 -08: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
Robert Speicher 72a7b30c9f Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
Grzegorz Bizon 0430b76441 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
Douwe Maan 43b1750892 Revert "Remove changes that are not absolutely necessary"
This reverts commit b0498c176f
2017-05-24 20:59:26 +00:00
Douwe Maan b0498c176f Remove changes that are not absolutely necessary 2017-05-23 20:38:35 -05:00
Douwe Maan ed16c351c5 Fix specs 2017-05-23 20:38:26 -05:00
James Lopez bdcd23b297 Create subgroups if they don't exist while importing projects 2017-04-05 10:09:31 +00:00
Stan Hu 07415e474e Fix Error 500 when Bitbucket importer does not have authorization
Closes #29739
2017-03-20 22:17:46 -07:00
Robert Speicher 4642ca6686 Use `empty_project` where possible in controller specs 2017-01-25 17:14:38 -05:00
Rémy Coutable e046e4c14d Namespace access token session key in `Import::GithubController`
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
Rémy Coutable 103114e3d7 Rename Gogs to Gitea, DRY the controller and improve views
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-19 17:35:51 +01:00
Stan Hu 7953480646 Fix remaining Bitbucket controller specs 2016-11-21 16:47:30 -08:00
Stan Hu af6926283b Fix Bitbucket status controller spec 2016-11-21 16:47:30 -08:00
Stan Hu 7ba65d05af Fix Bitbucket callback spec 2016-11-21 16:47:30 -08:00
James Lopez 0c65112da7 modify github import JS and controller so we can now specify a namespace and/or name for a project.
- Fixed and added specs.
- Added different namespace options depending on user privilages
- Updated docs.
2016-09-20 10:14:39 +02:00
Douglas Barbosa Alexandre 325de662ce Don't create groups for unallowed users when importing projects 2016-08-31 12:55:45 -03:00
Z.J. van de Weg 4c8e9a8d27 Remove gitorious 2016-08-25 10:10:10 +01:00
Eric K Idema 12aa1f898d Import from Github using Personal Access Tokens.
This stands as an alternative to using OAuth to access a user's Github
repositories.  This is setup in such a way that it can be used without OAuth
configuration.

From a UI perspective, the how to import modal has been replaced by a full
page, which includes a form for posting a personal access token back to the
Import::GithubController.

If the user has logged in via GitHub, skip the Personal Access Token and go
directly to Github for an access token via OAuth.
2016-06-30 18:48:17 +02:00
Kamil Trzcinski a0adafddd0 Remove require_relative 'import_spec_helper' 2016-06-08 18:18:49 +02:00
Kamil Trzcinski 9560639e81 Move ImportSpecHelper to spec/support/ 2016-06-08 17:21:08 +02:00