fix(instanceUrl): heuristic now supports git remote URLs
The fix mentioned in this MR title is the only observable change in behaviour, but the main motivation was to take the "get GitLab instance URL" logic out of the GitService
where it was causing massive complexity.
History
Originally, the extension supported only configured GitLab instance URL. It was easy to get it:
const { instanceUrl } = vscode.workspace.getConfiguration('gitlab');
This result always contained an URL (possibly default https://gitlab.com
).
Then we introduce a heuristic that says: "If there is no URL configured, try to match the git remote
URLs against URLs for which we configured access token.
This made the logic to retrieve instanceUrl
much more complex because we need to call git
.
We put this logic into GitService
to begin with !90 (merged).
This change
There was a circular dependency between the fetchCurrentInstanceUrl()
function and the rest of the GitService
. This MR solves it by duplicating the function that invokes git
using the execa
library. (this is subject to change very soon when we migrate to the native VS Code Git extension #203 (closed)).
Untangling these two concerns made the resulting code much clearer.
before | after |
---|---|
How to review
The best way would be to review the change commit by commit, where only the last commit changes (fixes) behaviour, the previous commits are only moving code around.
Related to #265 (closed)