45 lines
3.6 KiB
JavaScript
45 lines
3.6 KiB
JavaScript
"use strict";
|
|
/* ---------------------------------------------- *
|
|
* ------------------ classes ------------------- *
|
|
* ---------------------------------------------- */
|
|
class GitRepo {
|
|
constructor(stringArg, tokenArg) {
|
|
let regexMatches = gitRegex(stringArg);
|
|
this.host = regexMatches[1];
|
|
this.user = regexMatches[2];
|
|
this.repo = regexMatches[3];
|
|
this.accessToken = tokenArg;
|
|
this.sshUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'ssh');
|
|
this.httpsUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'https');
|
|
}
|
|
}
|
|
exports.GitRepo = GitRepo;
|
|
/* ---------------------------------------------- *
|
|
* ------------------ helpers ------------------- *
|
|
* ---------------------------------------------- */
|
|
let gitRegex = function (stringArg) {
|
|
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
|
|
let regexMatches = regexString.exec(stringArg);
|
|
return regexMatches;
|
|
};
|
|
let gitLink = function (hostArg, userArg, repoArg, tokenArg = '', linkTypeArg) {
|
|
let returnString;
|
|
if (tokenArg !== '') {
|
|
tokenArg = tokenArg + '@';
|
|
}
|
|
switch (linkTypeArg) {
|
|
case 'https':
|
|
returnString = 'https://' +
|
|
tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git';
|
|
break;
|
|
case 'ssh':
|
|
returnString = 'git@' +
|
|
hostArg + ':' + userArg + '/' + repoArg + '.git';
|
|
break;
|
|
default:
|
|
console.error('Link Type ' + linkTypeArg + ' not known');
|
|
break;
|
|
}
|
|
return returnString;
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZ2l0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuZ2l0LnRzIl0sIm5hbWVzIjpbXS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