@altostra/core
Version:
Core library for shared types and logic
1 lines • 3.68 kB
JavaScript
;var _BitbucketGitUtils_instances,_BitbucketGitUtils_account,_BitbucketGitUtils__hostedRepositoryRXs,_BitbucketGitUtils_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.BitbucketGitUtils=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"),REPO_URL_RX=/^https:\/\/bitbucket\.org\/[^/]+\/([^/]+)/i,REPO_NAME_RX_GROUP_INDEX=1;class BitbucketGitUtils{constructor({userAccount:t}){_BitbucketGitUtils_instances.add(this),_BitbucketGitUtils_account.set(this,void 0),_BitbucketGitUtils__hostedRepositoryRXs.set(this,void 0),__classPrivateFieldSet(this,_BitbucketGitUtils_account,t,"f"),__classPrivateFieldSet(this,_BitbucketGitUtils__hostedRepositoryRXs,new Lazy_1.Lazy(()=>hostedRepositoryUrlRXs(t)),"f")}getAccountName(){return __classPrivateFieldGet(this,_BitbucketGitUtils_account,"f")}isHostedRepository(t){return(0,Common_1.isHostedRepository)(__classPrivateFieldGet(this,_BitbucketGitUtils_instances,"a",_BitbucketGitUtils_hostedRepositoryRXs_get),t)}getAccountURL(){return Url_1.asUrl`https://bitbucket.org/${__classPrivateFieldGet(this,_BitbucketGitUtils_account,"f")}`}getRepositoryBrowserUrl(t){return this.getAccountURL()+Url_1.asUrl`/${t}`}getFileBrowserUrl(t,e,i){return this.getRepositoryBrowserUrl(t)+Url_1.asUrl`/src/${e}/${(0,common_1.filePathAsUrl)(i)}`}getRepositoryCloneUrl(t,e){switch(e){case"https":return Url_1.asUrl`https://bitbucket.org/${__classPrivateFieldGet(this,_BitbucketGitUtils_account,"f")}/${t}.git`;case"ssh":return Url_1.asUrl`git@bitbucket.org:${__classPrivateFieldGet(this,_BitbucketGitUtils_account,"f")}/${t}.git`}}getPullRequestsBrowserUrl(t){return this.getRepositoryBrowserUrl(t)+"/pull-requests"}getRepositoryNameFromBrowserUrl(t){const e=REPO_URL_RX.exec(t);if(!e)throw Errors_1.AltoError.create("Invalid repository url",{data:{repositoryUrl:t}});const[,i]=e;return(0,NonEmptyString_1.nonEmptyString)(i)}getRepositoryNameFromUrl(t){return(0,Common_1.getRepositoryNameFromUrl)(__classPrivateFieldGet(this,_BitbucketGitUtils_instances,"a",_BitbucketGitUtils_hostedRepositoryRXs_get),1,t)}}function hostedRepositoryUrlRXs(t){return[RegExp_1.regexp`^https:\/\/bitbucket\.org\/${t}\/([^\/]+)`,RegExp_1.regexp`^https:\/\/(?:[^\/@]+@)?bitbucket\.org\/${t}\/([^\/.]+).git$`,RegExp_1.regexp`^git@bitbucket\.org:${t}\/([^\/.]+).git$`]}exports.BitbucketGitUtils=BitbucketGitUtils,_BitbucketGitUtils_account=new WeakMap,_BitbucketGitUtils__hostedRepositoryRXs=new WeakMap,_BitbucketGitUtils_instances=new WeakSet,_BitbucketGitUtils_hostedRepositoryRXs_get=function(){return __classPrivateFieldGet(this,_BitbucketGitUtils__hostedRepositoryRXs,"f").value};