58 lines
7.6 KiB
JavaScript
58 lines
7.6 KiB
JavaScript
/// <reference path="./typings/main.d.ts" />
|
|
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;
|
|
})();
|
|
/* ---------------------------------------------- *
|
|
* ------------------ helpers ------------------- *
|
|
* ---------------------------------------------- */
|
|
var gitRegex = function (stringArg) {
|
|
var regexString = /(?:git\+|git\@|https\:\/\/|)(?:https\:\/\/|)([^\/|\:]*)(?:\/|:)([^\/]+)*(?:\/|:)([^\.]+)/;
|
|
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;
|
|
};
|
|
/* ---------------------------------------------- *
|
|
* ------------------ exports ------------------- *
|
|
* ---------------------------------------------- */
|
|
var git = function (stringArg, tokenArg) {
|
|
var localGitRepo = new gitRepo(stringAr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