smartstring/dist/smartstring.git.js

45 lines
3.6 KiB
JavaScript
Raw Normal View History

"use strict";
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;
2016-10-31 23:22:38 +00:00
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-02-23 06:06:54 +00:00
}
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)/;
2016-07-17 15:30:26 +00:00
let regexMatches = regexString.exec(stringArg);
2016-02-23 06:06:54 +00:00
return regexMatches;
};
2016-10-31 23:22:38 +00:00
let gitLink = function (hostArg, userArg, repoArg, tokenArg = '', linkTypeArg) {
2016-07-17 15:30:26 +00:00
let returnString;
2016-10-31 23:22:38 +00:00
if (tokenArg !== '') {
tokenArg = tokenArg + '@';
2016-02-23 06:06:54 +00:00
}
switch (linkTypeArg) {
2016-10-31 23:22:38 +00:00
case 'https':
returnString = 'https://' +
tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git';
2016-02-23 06:06:54 +00:00
break;
2016-10-31 23:22:38 +00:00
case 'ssh':
returnString = 'git@' +
hostArg + ':' + userArg + '/' + repoArg + '.git';
2016-02-23 06:06:54 +00:00
break;
default:
2016-10-31 23:22:38 +00:00
console.error('Link Type ' + linkTypeArg + ' not known');
2016-02-23 06:06:54 +00:00
break;
}
return returnString;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZ2l0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuZ2l0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQTs7b0RBRW9EO0FBQ3BEO0lBT0ksWUFBWSxTQUFpQixFQUFDLFFBQWlCO1FBQzNDLElBQUksWUFBWSxHQUFHLFFBQVEsQ0FBQyxTQUFTLENBQUMsQ0FBQTtRQUN0QyxJQUFJLENBQUMsSUFBSSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUMzQixJQUFJLENBQUMsSUFBSSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUMzQixJQUFJLENBQUMsSUFBSSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUMzQixJQUFJLENBQUMsV0FBVyxHQUFHLFFBQVEsQ0FBQTtRQUMzQixJQUFJLENBQUMsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFDLElBQUksQ0FBQyxJQUFJLEVBQUMsSUFBSSxDQUFDLElBQUksRUFBQyxJQUFJLENBQUMsV0FBVyxFQUFFLEtBQUssQ0FBQyxDQUFBO1FBQzVFLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUMsSUFBSSxDQUFDLElBQUksRUFBQyxJQUFJLENBQUMsSUFBSSxFQUFDLElBQUksQ0FBQyxXQUFXLEVBQUUsT0FBTyxDQUFDLENBQUE7SUFDcEYsQ0FBQztDQUNKO0FBaEJELDBCQWdCQztBQUVEOztvREFFb0Q7QUFDcEQsSUFBSSxRQUFRLEdBQUcsVUFBUyxTQUFnQ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