smartstring/dist/smartstring.git.js

47 lines
3.7 KiB
JavaScript
Raw Normal View History

"use strict";
2016-07-17 15:30:26 +00:00
const plugins = require("./smartstring.plugins");
2016-02-23 06:06:54 +00:00
/* ---------------------------------------------- *
* ------------------ classes ------------------- *
* ---------------------------------------------- */
2016-07-17 15:30:26 +00:00
class GitRepo {
constructor(stringArg, tokenArg) {
let regexMatches = gitRegex(stringArg);
2016-02-23 06:06:54 +00:00
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");
}
;
2016-07-17 15:30:26 +00:00
}
2016-05-25 03:06:19 +00:00
exports.GitRepo = GitRepo;
2016-02-23 06:06:54 +00:00
/* ---------------------------------------------- *
* ------------------ helpers ------------------- *
* ---------------------------------------------- */
2016-07-17 15:30:26 +00:00
let gitRegex = function (stringArg) {
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
let regexMatches = regexString.exec(stringArg);
2016-02-23 06:06:54 +00:00
return regexMatches;
};
2016-07-17 15:30:26 +00:00
let gitLink = function (hostArg, userArg, repoArg, tokenArg = "", linkTypeArg) {
let returnString;
2016-02-23 06:06:54 +00:00
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;
};
2016-07-17 15:30:26 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZ2l0LmpzIiwic291cmNlUm9vdCI6IiIsInNv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