refactor: move methods in GitService class and log git errors
This MR is last of the #145 (closed) series. It does two main things:
- moves all methods in
git_service.js
toGitService
class
- adds log function to
GitService
so we can log git related errors
git_service.js
to GitService
class
move all methods in This change is almost the whole MR diff. We are not changing the git_service.js
interface or the module behaviour.
This MR is the very reason I introduced a full test suite for git_service.js
in !93 (merged). The GitService
class
has been created in !93 (merged) but to keep that MR size down, the MR only forwarded to the functions defined in the git_service.js
file.
Moving the the functions to GitService
class has been done one function at a time and it might be best to follow the commits. When all functions move to GitService
class
, we reduce the need to pass the class properties (e.g. workspaceFolder
) as arguments to every function call.
GitService
so we can log git related errors
add log function to The GitService
class
is not dependent on vscode
so we can unit test it. That means we can't use the vscode.gitLabWorkflow.log
global function directly (as we do everywhere else in the code) and we are instead passing it down in the constructor.
The main concern was this original code:
try {
output = await execa.stdout(git, args, {
cwd: currentWorkspaceFolder,
preferLocal: false,
});
} catch (ex) {
// Fail siletly
}
In the future, we will wrap the exception and throw it, but at the moment the whole extension is built around expecting that the GitService.fetch()
the method can return undefined
. So for now, we'll only log the error but return undefined
as the extension expects.
Part of #145 (closed)