@codefresh-io/cf-git-providers
Version:
An NPM module/CLI for interacting with various git providers
28 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSshCloneUrl = exports.DEFAULT_GERRIT_SSH_PORT = void 0;
exports.DEFAULT_GERRIT_SSH_PORT = 29418;
function getSshCloneUrl(repoName, username, hostname, gitliesCloneUrl) {
const sshRepoUrlFallback = `ssh://${username}@${hostname}:${exports.DEFAULT_GERRIT_SSH_PORT}/${repoName}`;
if (!gitliesCloneUrl)
return sshRepoUrlFallback;
const gitliesCloneUrlHasHttpPrefixes = /^https?:\/\//.test(gitliesCloneUrl);
if (gitliesCloneUrlHasHttpPrefixes)
return sshRepoUrlFallback;
// e.g. ssh://user@gerrit.com:29418/test-repo || user@gerrit.com:29418/test-repo
const correctSshLink = /^(ssh:\/\/)?.+@.+:\d{2,5}\/.+/.test(gitliesCloneUrl);
if (correctSshLink) {
return gitliesCloneUrl;
}
// ssh://{site}:{port}/{repo}
const sshLinkDoesntIncludeUsername = /^ssh:\/\/[^@]+:\d{2,5}\/.+/.test(gitliesCloneUrl);
if (sshLinkDoesntIncludeUsername) {
const desiredUrlPrefix = `ssh://${username}@`;
return gitliesCloneUrl.replace(/^ssh:\/\//, desiredUrlPrefix);
}
// {site.com}/{repo} || {site.com}:{port}/{repo}
// this might be regular url and maybe ssh, we don't know, so return fallback
return sshRepoUrlFallback;
}
exports.getSshCloneUrl = getSshCloneUrl;
//# sourceMappingURL=gerrit.helpers.js.map