@@ -2454,22 +2454,50 @@ function getFetchUrl(settings) {
24542454 return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
24552455}
24562456function getServerUrl(url) {
2457- let urlValue = url && url.trim().length > 0
2458- ? url
2459- : process.env['GITHUB_SERVER_URL'] || 'https://github.com';
2460- return new url_1.URL(urlValue);
2457+ let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
2458+ if (hasContent(url, WhitespaceMode.Trim)) {
2459+ resolvedUrl = url;
2460+ }
2461+ return new url_1.URL(resolvedUrl);
24612462}
24622463function getServerApiUrl(url) {
2463- let apiUrl = 'https://api.github.com';
2464- if (isGhes(url)) {
2465- const serverUrl = getServerUrl(url);
2466- apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString();
2464+ if (hasContent(url, WhitespaceMode.Trim)) {
2465+ let serverUrl = getServerUrl(url);
2466+ if (isGhes(url)) {
2467+ serverUrl.pathname = 'api/v3';
2468+ }
2469+ else {
2470+ serverUrl.hostname = 'api.' + serverUrl.hostname;
2471+ }
2472+ return pruneSuffix(serverUrl.toString(), '/');
24672473 }
2468- return apiUrl ;
2474+ return process.env['GITHUB_API_URL'] || 'https://api.github.com' ;
24692475}
24702476function isGhes(url) {
2471- const ghUrl = getServerUrl(url);
2472- return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
2477+ const ghUrl = new url_1.URL(url || process.env['GITHUB_SERVER_URL'] || 'https://github.com');
2478+ const hostname = ghUrl.hostname.trimEnd().toUpperCase();
2479+ const isGitHubHost = hostname === 'GITHUB.COM';
2480+ const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
2481+ const isLocalHost = hostname.endsWith('.LOCALHOST');
2482+ return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
2483+ }
2484+ function pruneSuffix(text, suffix) {
2485+ if (hasContent(suffix, WhitespaceMode.Preserve) && (text === null || text === void 0 ? void 0 : text.endsWith(suffix))) {
2486+ return text.substring(0, text.length - suffix.length);
2487+ }
2488+ return text;
2489+ }
2490+ var WhitespaceMode;
2491+ (function (WhitespaceMode) {
2492+ WhitespaceMode[WhitespaceMode["Trim"] = 0] = "Trim";
2493+ WhitespaceMode[WhitespaceMode["Preserve"] = 1] = "Preserve";
2494+ })(WhitespaceMode || (WhitespaceMode = {}));
2495+ function hasContent(text, whitespaceMode) {
2496+ let refinedText = text !== null && text !== void 0 ? text : '';
2497+ if (whitespaceMode == WhitespaceMode.Trim) {
2498+ refinedText = refinedText.trim();
2499+ }
2500+ return refinedText.length > 0;
24732501}
24742502
24752503
0 commit comments