Consistent handling of remotes, instances and branches
Problem to solve
With the implementation of !90 (merged) we started discovering several classes of errors related to parsing information about the workspace git repository.
The main issue is the complex edge cases that were never considered (sorted by how frequently they occur):
- Mutiple remotes in one repository
- here we can get a remote that is not matching the defined
instanceUrl(more details: #115 (comment 410341027))
- here we can get a remote that is not matching the defined
- Multi-root workspaces
- Which remote,
instanceUrland branch to use when there are multiple git repositories in one workspace? - currently, we use the open file to find out what git repository should we use, but if there's no file open we have very inconsistent handling
- Which remote,
- Tracking branches
- sometimes we ask for tracking branch which can again point to a different remote than what we use for rest of the requests
Proposal
Separate the current GitService into three modules with different responsibilities:
- thin layer on top of the
gitshell command - instanceUrl service that would be responsible for matching git remotes and define tokens
- GitLab-specific git logic (e.g. picking which remote to use based on an instanceUrl, creating GitLab API URL based on git remote)
The last service would return an object with the following attributes:
-
apiUrl- where to send API requests -
namespace- group or username -
project- project name -
branch(optional) - remote branch (e.g. to query for active pipelines)
Further details
The main benefit of the proposed solution is that we would have certainty that our instanceUrl matches the namespace, project, and branch information. This would reduce hard to remove issues and it would improve the environment for contributors because the current edge-case ridden code is very hard to understand.
We also have two config options that override the aforementioned logic:
"gitlab.remoteName": {
"type": "string",
"default": null,
"description": "Name of the git remote to use in order to locate the Gitlab project"
},
"gitlab.pipelineGitRemoteName": {
"type": "string",
"default": null,
"description": "Name of the git remote to use in order to locate the Gitlab project for your pipeline. Keep empty for default"
},