Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4c5a11

Browse filesBrowse files
authored
Revise isGhes logic (actions#963)
* Revise `isGhes` logic * ran `npm run format` * add unit test * ran `npm run format`
1 parent 19dfb7b commit f4c5a11
Copy full SHA for f4c5a11

File tree

Expand file treeCollapse file tree

3 files changed

+51
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+51
-2
lines changed

‎__tests__/utils.test.ts

Copy file name to clipboardExpand all lines: __tests__/utils.test.ts
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getVersionInputFromPlainFile,
1414
getVersionInputFromTomlFile,
1515
getNextPageUrl,
16+
isGhes,
1617
IS_WINDOWS,
1718
getDownloadFileName
1819
} from '../src/utils';
@@ -195,3 +196,41 @@ describe('getDownloadFileName', () => {
195196
}
196197
});
197198
});
199+
200+
describe('isGhes', () => {
201+
const pristineEnv = process.env;
202+
203+
beforeEach(() => {
204+
jest.resetModules();
205+
process.env = {...pristineEnv};
206+
});
207+
208+
afterAll(() => {
209+
process.env = pristineEnv;
210+
});
211+
212+
it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => {
213+
delete process.env['GITHUB_SERVER_URL'];
214+
expect(isGhes()).toBeFalsy();
215+
});
216+
217+
it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => {
218+
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
219+
expect(isGhes()).toBeFalsy();
220+
});
221+
222+
it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => {
223+
process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com';
224+
expect(isGhes()).toBeFalsy();
225+
});
226+
227+
it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => {
228+
process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost';
229+
expect(isGhes()).toBeFalsy();
230+
});
231+
232+
it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => {
233+
process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com';
234+
expect(isGhes()).toBeTruthy();
235+
});
236+
});

‎dist/setup/index.js

Copy file name to clipboardExpand all lines: dist/setup/index.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92017,7 +92017,11 @@ function validatePythonVersionFormatForPyPy(version) {
9201792017
exports.validatePythonVersionFormatForPyPy = validatePythonVersionFormatForPyPy;
9201892018
function isGhes() {
9201992019
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
92020-
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
92020+
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
92021+
const isGitHubHost = hostname === 'GITHUB.COM';
92022+
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
92023+
const isLocalHost = hostname.endsWith('.LOCALHOST');
92024+
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
9202192025
}
9202292026
exports.isGhes = isGhes;
9202392027
function isCacheFeatureAvailable() {

‎src/utils.ts

Copy file name to clipboardExpand all lines: src/utils.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ export function isGhes(): boolean {
116116
const ghUrl = new URL(
117117
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
118118
);
119-
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
119+
120+
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
121+
const isGitHubHost = hostname === 'GITHUB.COM';
122+
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
123+
const isLocalHost = hostname.endsWith('.LOCALHOST');
124+
125+
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
120126
}
121127

122128
export function isCacheFeatureAvailable(): boolean {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.