Import from GitHub API can ignore target_namespace
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary When importing from GitHub, the required `target_namespace` parameter will create groups/subgroups as needed. There are some instances in which the group creation happens but the project import will fall back to the user's namespace. <!-- Summarize the bug encountered concisely. --> ### Steps to reproduce - for GitLab: Use a group access token - Import a GH project using the [GitLab API](https://docs.gitlab.com/ee/api/import.html#import-repository-from-github) - Specify a subgroup that doesn't already exist for `target_namespace` This isn't guaranteed to happen. It seems like the importer will create subgroups as needed, so when importing multiple projects only the first one will fall under the bot account's namespace. This may be a race condition, so if group creation is delayed the bot account will inherit the project and subsequent imports will work as expected. <!-- Describe how one can reproduce the issue - this is very important. Please use an ordered list. --> ### Example Project N/A <!-- If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report. If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version. --> ### What is the current *bug* behavior? Some imports go to the bot account's namespace when using the GH import and a group is created ### What is the expected *correct* behavior? We should not fall back to the user namespace if the `target_namespace` is blank or doesn't exist, which is what currently happens. `target_namespace` is required attribute, if passed as blank, user should see an error, like target_namespace cannot be blank. Please provide an existing namespace. The user needs to provide an existing namespace which can be their own user namespace or an existing group that they have permission to import a project into. If the conditions don't match we should return an error to the user in UI and API before importing or creating anything. In other words, if user wants to import to a group and has no group on GitLab they can import into, they should first create a group. This info should be added to error message that user receives with failed attempt. This all needs to be documented. /cc @eread <!-- Describe what you should see instead. --> ### Relevant logs and/or screenshots <!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. --> ### Output of checks <!-- If you are reporting a bug on GitLab.com, uncomment below --> This bug happens on GitLab.com **[See logs here for example (internal only)](https://log.gprd.gitlab.net/goto/48b4c510-5fb1-11ed-8d37-e9a2f393ea2a)** **[See ticket (internal only) for more exampes](https://gitlab.zendesk.com/agent/tickets/343139)** <!-- /label ~"reproduced on GitLab.com" --> #### Results of GitLab environment info N/A #### Results of GitLab application Check N/A ### Possible fixes Fix affects GitHub and Gitea importers.
issue