@altostra/core
Version:
Core library for shared types and logic
1 lines • 3.55 kB
JavaScript
;var _GitLabGitUtils_instances,_GitLabGitUtils_groupName,_GitLabGitUtils__hostedRepositoryRXs,_GitLabGitUtils_hostedRepositoryRXs_get,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(t,e,i,r,s){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?s.call(t,i):s?s.value=i:e.set(t,i),i},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GitLabGitUtils=void 0;const NonEmptyString_1=require("../../../common/CustomTypes/NonEmptyString"),Errors_1=require("../../../common/Errors"),Lazy_1=require("../../../common/Utils/Lazy"),RegExp_1=require("../../../common/Utils/RegExp"),Url_1=require("../../../common/Utils/Url"),Common_1=require("../../Common"),common_1=require("../common"),common_2=require("./common"),REPO_URL_RX=/^https:\/\/gitlab.com\/[^/]+\/([^/]+)/,REPO_NAME_RX_GROUP_INDEX=1;class GitLabGitUtils{constructor({groupName:t}){_GitLabGitUtils_instances.add(this),_GitLabGitUtils_groupName.set(this,void 0),_GitLabGitUtils__hostedRepositoryRXs.set(this,void 0),__classPrivateFieldSet(this,_GitLabGitUtils_groupName,t,"f"),__classPrivateFieldSet(this,_GitLabGitUtils__hostedRepositoryRXs,new Lazy_1.Lazy(()=>[RegExp_1.regexp`^https:\/\/gitlab\.com\/${t}\/([^\/.]+)(?:\.git)?$`,RegExp_1.regexp`^git@gitlab\.com:${t}\/([^\/.]+).git$`]),"f")}getAccountName(){return __classPrivateFieldGet(this,_GitLabGitUtils_groupName,"f")}isHostedRepository(t){return(0,Common_1.isHostedRepository)(__classPrivateFieldGet(this,_GitLabGitUtils_instances,"a",_GitLabGitUtils_hostedRepositoryRXs_get),t)}getAccountURL(){return(0,NonEmptyString_1.nonEmptyString)(common_2.GITLAB_BASE_URL+Url_1.asUrl`/${__classPrivateFieldGet(this,_GitLabGitUtils_groupName,"f")}`)}getRepositoryBrowserUrl(t){return this.getAccountURL()+Url_1.asUrl`/${t}`}getFileBrowserUrl(t,e,i){return this.getRepositoryBrowserUrl(t)+Url_1.asUrl`/-/blob/${e}/${(0,common_1.filePathAsUrl)(i)}`}getPullRequestsBrowserUrl(t){return this.getRepositoryBrowserUrl(t)+"/-/merge_requests"}getRepositoryCloneUrl(t,e){switch(e){case"https":return Url_1.asUrl`https://gitlab.com/${__classPrivateFieldGet(this,_GitLabGitUtils_groupName,"f")}/${t}.git`;case"ssh":return Url_1.asUrl`git@gitlab.com:${__classPrivateFieldGet(this,_GitLabGitUtils_groupName,"f")}/${t}.git`}}getRepositoryNameFromBrowserUrl(t){const e=REPO_URL_RX.exec(t),i=null==e?void 0:e[1];if(!(0,NonEmptyString_1.isNonEmptyString)(i))throw Errors_1.AltoError.create("Invalid repository url",{data:{repositoryUrl:t}});return i}getRepositoryNameFromUrl(t){return(0,Common_1.getRepositoryNameFromUrl)(__classPrivateFieldGet(this,_GitLabGitUtils_instances,"a",_GitLabGitUtils_hostedRepositoryRXs_get),1,t)}}exports.GitLabGitUtils=GitLabGitUtils,_GitLabGitUtils_groupName=new WeakMap,_GitLabGitUtils__hostedRepositoryRXs=new WeakMap,_GitLabGitUtils_instances=new WeakSet,_GitLabGitUtils_hostedRepositoryRXs_get=function(){return __classPrivateFieldGet(this,_GitLabGitUtils__hostedRepositoryRXs,"f").value};