Skip to content

refactor: handle multiple GitLab projects in one Git repository

Tomas Vik requested to merge 558-handling-multiple-projects into main

This MR extends our new project-centric model by adding handling for a situation where there are multiple detected repositories for a single repository.

select-from-multiple-projects

This happens often when you fork a project, or the extension where we have a security remote:

$ git remote -v
origin	git@gitlab.com:gitlab-org/gitlab-vscode-extension.git (fetch)
origin	git@gitlab.com:gitlab-org/gitlab-vscode-extension.git (push)
security	git@gitlab.com:gitlab-org/security/gitlab-vscode-extension.git (fetch)
security	git@gitlab.com:gitlab-org/security/gitlab-vscode-extension.git (push)

In this scenario, the extension detects multiple GitLab projects and has to let the user choose which one should it use.

This MR also adds a command that lets you choose a project for a repository:

select-project-with-command

The flow in this MR

You can follow this flow to understand what the extension does:

  1. We detect multiple projects in GitLabProjectRepository.detectProjects
  2. The IssuableDataProvider.getNewChildren() shows MultipleProjectsItem, which alerts the user that multiple projects are in the repository.
  3. User clicks the item, which will trigger the ROGRAMMATIC_COMMANDS.SELECT_PROJECT command, running the select_project.ts logic.
  4. User selects a project. The new SelectedProjectSetting gets stored in the SelectedProjectStore.
  5. SelectedProjectStore triggered an event. The GitLabProjectRepository listens on this event and starts initializing projects again
  6. This time, the GitLabProjectRepository.addSelectedProjects marks the selected project
  7. IssuableDataProvider.getNewChildren() renders the project item because even though there are multiple detected projects, one of them is selected.
Edited by Tomas Vik

Merge request reports