2016-07-06 08:04:25 +00:00
|
|
|
import * as plugins from "./smartstring.plugins";
|
2016-02-23 06:06:54 +00:00
|
|
|
|
|
|
|
/* ---------------------------------------------- *
|
|
|
|
* ------------------ classes ------------------- *
|
|
|
|
* ---------------------------------------------- */
|
2016-05-25 03:06:19 +00:00
|
|
|
export class GitRepo {
|
2016-02-23 06:06:54 +00:00
|
|
|
host:string;
|
|
|
|
user:string;
|
|
|
|
repo:string;
|
|
|
|
accessToken:string;
|
|
|
|
sshUrl:string;
|
|
|
|
httpsUrl:string;
|
|
|
|
constructor(stringArg:string,tokenArg?:string){
|
|
|
|
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");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------- *
|
|
|
|
* ------------------ helpers ------------------- *
|
|
|
|
* ---------------------------------------------- */
|
|
|
|
let gitRegex = function(stringArg:string){
|
2016-06-05 07:31:10 +00:00
|
|
|
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-]*)(?:\/)([a-zA-Z0-9\-]*)(?:\.git)/;
|
2016-02-23 06:06:54 +00:00
|
|
|
let regexMatches = regexString.exec(stringArg);
|
|
|
|
return regexMatches;
|
|
|
|
};
|
|
|
|
|
|
|
|
let gitLink = function(hostArg:string, userArg:string, repoArg:string, tokenArg:string = "", linkTypeArg):string{
|
|
|
|
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:
|
|
|
|
plugins.beautylog.error("Link Type " + linkTypeArg + " not known");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return returnString;
|
2016-05-01 12:02:48 +00:00
|
|
|
};
|