2022-03-18 21:50:24 +00:00
|
|
|
import * as plugins from './smartstring.plugins.js';
|
2016-02-23 06:06:54 +00:00
|
|
|
|
|
|
|
/* ---------------------------------------------- *
|
|
|
|
* ------------------ classes ------------------- *
|
|
|
|
* ---------------------------------------------- */
|
2016-05-25 03:06:19 +00:00
|
|
|
export class GitRepo {
|
2018-07-21 12:37:39 +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');
|
2017-10-05 13:55:59 +00:00
|
|
|
}
|
2016-02-23 06:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------- *
|
|
|
|
* ------------------ helpers ------------------- *
|
|
|
|
* ---------------------------------------------- */
|
2020-12-31 03:56:40 +00:00
|
|
|
const gitRegex = function (stringArg: string) {
|
2022-03-18 21:52:38 +00:00
|
|
|
const regexString =
|
2023-06-26 07:57:32 +00:00
|
|
|
/([a-zA-Z0-9\-_\.]*)(?:\/|\:)([a-zA-Z0-9\-_\.]*)(?:\/)([a-zA-Z0-9\-_\.]*)(?:\.git)/;
|
2018-07-21 12:37:39 +00:00
|
|
|
let regexMatches = regexString.exec(stringArg);
|
|
|
|
return regexMatches;
|
|
|
|
};
|
2016-02-23 06:06:54 +00:00
|
|
|
|
2020-12-31 03:56:40 +00:00
|
|
|
const gitLink = function (
|
2018-07-21 12:37:39 +00:00
|
|
|
hostArg: string,
|
|
|
|
userArg: string,
|
|
|
|
repoArg: string,
|
|
|
|
tokenArg: string = '',
|
|
|
|
linkTypeArg
|
|
|
|
): string {
|
|
|
|
let returnString;
|
2017-10-05 13:55:59 +00:00
|
|
|
if (tokenArg !== '') {
|
2018-07-21 12:37:39 +00:00
|
|
|
tokenArg = tokenArg + '@';
|
2017-10-05 13:55:59 +00:00
|
|
|
}
|
|
|
|
switch (linkTypeArg) {
|
|
|
|
case 'https':
|
2018-07-21 12:37:39 +00:00
|
|
|
returnString = 'https://' + tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git';
|
|
|
|
break;
|
2017-10-05 13:55:59 +00:00
|
|
|
case 'ssh':
|
2018-07-21 12:37:39 +00:00
|
|
|
returnString = 'git@' + hostArg + ':' + userArg + '/' + repoArg + '.git';
|
|
|
|
break;
|
2017-10-05 13:55:59 +00:00
|
|
|
default:
|
2018-07-21 12:37:39 +00:00
|
|
|
console.error('Link Type ' + linkTypeArg + ' not known');
|
|
|
|
break;
|
2017-10-05 13:55:59 +00:00
|
|
|
}
|
2018-07-21 12:37:39 +00:00
|
|
|
return returnString;
|
|
|
|
};
|