Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/dist/index.js
diff options
context:
space:
mode:
authorJohn Wesley Walker III <81404201+jww3@users.noreply.github.com>2024-10-18 10:07:17 +0200
committerGitHub <noreply@github.com>2024-10-18 10:07:17 +0200
commit06229e648730e5ff920410853f1f4ec7dacf988f (patch)
tree7b837757825893756369dd882fde4f781ac541d1 /dist/index.js
parent95a822ba46f3b23eaa3dc6f36ee1f54d313fb694 (diff)
`url-helper.ts` now leverages well-known environment variables. (#1941)
* `utl-helper.ts` now leverages well-known environment variables. --------- Co-authored-by: Erez Testiler <easyt@github.com>
Diffstat (limited to 'dist/index.js')
-rw-r--r--dist/index.js50
1 files changed, 39 insertions, 11 deletions
diff --git a/dist/index.js b/dist/index.js
index d86415e..b0db713 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2454,22 +2454,50 @@ function getFetchUrl(settings) {
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
}
function getServerUrl(url) {
- let urlValue = url && url.trim().length > 0
- ? url
- : process.env['GITHUB_SERVER_URL'] || 'https://github.com';
- return new url_1.URL(urlValue);
+ let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
+ if (hasContent(url, WhitespaceMode.Trim)) {
+ resolvedUrl = url;
+ }
+ return new url_1.URL(resolvedUrl);
}
function getServerApiUrl(url) {
- let apiUrl = 'https://api.github.com';
- if (isGhes(url)) {
- const serverUrl = getServerUrl(url);
- apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString();
+ if (hasContent(url, WhitespaceMode.Trim)) {
+ let serverUrl = getServerUrl(url);
+ if (isGhes(url)) {
+ serverUrl.pathname = 'api/v3';
+ }
+ else {
+ serverUrl.hostname = 'api.' + serverUrl.hostname;
+ }
+ return pruneSuffix(serverUrl.toString(), '/');
}
- return apiUrl;
+ return process.env['GITHUB_API_URL'] || 'https://api.github.com';
}
function isGhes(url) {
- const ghUrl = getServerUrl(url);
- return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
+ const ghUrl = new url_1.URL(url || process.env['GITHUB_SERVER_URL'] || 'https://github.com');
+ const hostname = ghUrl.hostname.trimEnd().toUpperCase();
+ const isGitHubHost = hostname === 'GITHUB.COM';
+ const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
+ const isLocalHost = hostname.endsWith('.LOCALHOST');
+ return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
+}
+function pruneSuffix(text, suffix) {
+ if (hasContent(suffix, WhitespaceMode.Preserve) && (text === null || text === void 0 ? void 0 : text.endsWith(suffix))) {
+ return text.substring(0, text.length - suffix.length);
+ }
+ return text;
+}
+var WhitespaceMode;
+(function (WhitespaceMode) {
+ WhitespaceMode[WhitespaceMode["Trim"] = 0] = "Trim";
+ WhitespaceMode[WhitespaceMode["Preserve"] = 1] = "Preserve";
+})(WhitespaceMode || (WhitespaceMode = {}));
+function hasContent(text, whitespaceMode) {
+ let refinedText = text !== null && text !== void 0 ? text : '';
+ if (whitespaceMode == WhitespaceMode.Trim) {
+ refinedText = refinedText.trim();
+ }
+ return refinedText.length > 0;
}