@altostra/core
Version:
Core library for shared types and logic
1 lines • 3.47 kB
JavaScript
;var _GitHubGitUtils_instances,_GitHubGitUtils_accountName,_GitHubGitUtils__hostedRepositoryRXs,_GitHubGitUtils_hostedRepositoryRXs_get,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(t,e,i,s,r){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?r.call(t,i):r?r.value=i:e.set(t,i),i},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(t,e,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GitHubGitUtils=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:\/\/github\.com\/[^/]+\/([^/]+)/i,REPO_NAME_RX_GROUP_INDEX=1;class GitHubGitUtils{constructor({accountName:t}){_GitHubGitUtils_instances.add(this),_GitHubGitUtils_accountName.set(this,void 0),_GitHubGitUtils__hostedRepositoryRXs.set(this,void 0),__classPrivateFieldSet(this,_GitHubGitUtils_accountName,t,"f"),__classPrivateFieldSet(this,_GitHubGitUtils__hostedRepositoryRXs,new Lazy_1.Lazy(()=>[RegExp_1.regexp`^https:\/\/github\.com\/${t}\/([^\/.]+)(?:\.git)?$`,RegExp_1.regexp`^git@github\.com:${t}\/([^\/.]+).git$`]),"f")}getAccountName(){return __classPrivateFieldGet(this,_GitHubGitUtils_accountName,"f")}isHostedRepository(t){return(0,Common_1.isHostedRepository)(__classPrivateFieldGet(this,_GitHubGitUtils_instances,"a",_GitHubGitUtils_hostedRepositoryRXs_get),t)}getAccountURL(){return Url_1.asUrl`https://github.com/${__classPrivateFieldGet(this,_GitHubGitUtils_accountName,"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)+"/pulls"}getRepositoryCloneUrl(t,e){switch(e){case"https":return Url_1.asUrl`https://github.com/${__classPrivateFieldGet(this,_GitHubGitUtils_accountName,"f")}/${t}.git`;case"ssh":return Url_1.asUrl`git@github.com:${__classPrivateFieldGet(this,_GitHubGitUtils_accountName,"f")}/${t}.git`}}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,_GitHubGitUtils_instances,"a",_GitHubGitUtils_hostedRepositoryRXs_get),1,t)}}exports.GitHubGitUtils=GitHubGitUtils,_GitHubGitUtils_accountName=new WeakMap,_GitHubGitUtils__hostedRepositoryRXs=new WeakMap,_GitHubGitUtils_instances=new WeakSet,_GitHubGitUtils_hostedRepositoryRXs_get=function(){return __classPrivateFieldGet(this,_GitHubGitUtils__hostedRepositoryRXs,"f").value};