49 lines
3.9 KiB
JavaScript
49 lines
3.9 KiB
JavaScript
"use strict";
|
|
var plugins = require("./smartstring.plugins");
|
|
/* ---------------------------------------------- *
|
|
* ------------------ classes ------------------- *
|
|
* ---------------------------------------------- */
|
|
var GitRepo = (function () {
|
|
function GitRepo(stringArg, tokenArg) {
|
|
var 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");
|
|
}
|
|
;
|
|
return GitRepo;
|
|
}());
|
|
exports.GitRepo = GitRepo;
|
|
/* ---------------------------------------------- *
|
|
* ------------------ helpers ------------------- *
|
|
* ---------------------------------------------- */
|
|
var gitRegex = function (stringArg) {
|
|
var regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
|
|
var regexMatches = regexString.exec(stringArg);
|
|
return regexMatches;
|
|
};
|
|
var gitLink = function (hostArg, userArg, repoArg, tokenArg, linkTypeArg) {
|
|
if (tokenArg === void 0) { tokenArg = ""; }
|
|
var 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:
|
|
plugins.beautylog.error("Link Type " + linkTypeArg + " not known");
|
|
break;
|
|
}
|
|
return returnString;
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZ2l0LmpzIiwic291cmNlUm9vdCI6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