I tried using Nodegit in the same method, but I got an error message saying "Clone.clone, stack: Error: Method clone has caused an error." or "Github authentitation failed."
I have tried it but it gives me below error message
Error: Method clone has thrown an error. {errno: -1, errorFunction: 'Clone.clone', stack: 'Error: Method clone has thrown an error.', message: 'Method clone has thrown an error.'}
class GitClient {
constructor(realname, email, token, username, repoName, branch, local) {
this.config = {
branch,
remote: "SSH URL",
local,
username,
realname,
email,
token
};
this.cloneOpts = {
callbacks: {
certificateCheck: () => { return 0; },
credentials: (url, username) => {
return NodeGit.Cred.sshKeyNew(
username,
path.join(this.config.local, '.ssh/id_rsa.pub'),
path.join(this.config.local, '.ssh/id_rsa'),
''
);
// return NodeGit.Cred.sshKeyFromAgent(username);
}
}
};
this.cloneOpts.fetchOpts = { callbacks: this.cloneOpts.callbacks };
}
async clone(options) {
this.cloneOpts.checkoutBranch = options.branch;
return NodeGit.Clone(options.remote, options.local, this.cloneOpts).then((data) => {
console.log(data)
return data;
}).catch(err => {
console.log(err);
});
}
}