From 7fcbcdce7d7b3a50a59e1b8a70636605230bfbf5 Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:15:26 +0000 Subject: [PATCH] ran `npm run format` --- __test__/url-helper.test.ts | 20 +++++++++++++++----- src/url-helper.ts | 13 +++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/__test__/url-helper.test.ts b/__test__/url-helper.test.ts index e3e810b..65773b9 100644 --- a/__test__/url-helper.test.ts +++ b/__test__/url-helper.test.ts @@ -14,10 +14,20 @@ describe('isGhes tests', () => { describe('getServerApiUrl tests', () => { it('basics', async () => { expect(urlHelper.getServerApiUrl()).toBe('https://api.github.com') - expect(urlHelper.getServerApiUrl('https://github.com')).toBe('https://api.github.com') - expect(urlHelper.getServerApiUrl('https://GitHub.com')).toBe('https://api.github.com') - expect(urlHelper.getServerApiUrl('https://europe.ghe.com')).toBe('https://api.europe.ghe.com') - expect(urlHelper.getServerApiUrl('https://australia.GHE.COM')).toBe('https://api.australia.ghe.com') - expect(urlHelper.getServerApiUrl('https://src.onpremise.customer.com')).toBe('https://src.onpremise.customer.com/api/v3') + expect(urlHelper.getServerApiUrl('https://github.com')).toBe( + 'https://api.github.com' + ) + expect(urlHelper.getServerApiUrl('https://GitHub.com')).toBe( + 'https://api.github.com' + ) + expect(urlHelper.getServerApiUrl('https://europe.ghe.com')).toBe( + 'https://api.europe.ghe.com' + ) + expect(urlHelper.getServerApiUrl('https://australia.GHE.COM')).toBe( + 'https://api.australia.ghe.com' + ) + expect( + urlHelper.getServerApiUrl('https://src.onpremise.customer.com') + ).toBe('https://src.onpremise.customer.com/api/v3') }) }) diff --git a/src/url-helper.ts b/src/url-helper.ts index 597021d..b12765c 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -33,9 +33,9 @@ export function getServerApiUrl(url?: string): string { if (hasContent(url, false)) { let serverUrl = getServerUrl(url) if (isGhes(url)) { - serverUrl.pathname = "api/v3" + serverUrl.pathname = 'api/v3' } else { - serverUrl.hostname = "api." + serverUrl.hostname + serverUrl.hostname = 'api.' + serverUrl.hostname } return pruneSuffix(serverUrl.toString(), '/') @@ -57,7 +57,6 @@ export function isGhes(url?: string): boolean { return !isGitHubHost && !isGheHost && !isLocalHost } - function pruneSuffix(text: string, suffix: string) { if (hasContent(suffix, true) && text?.endsWith(suffix)) { return text.substring(0, text.length - suffix.length) @@ -65,11 +64,13 @@ function pruneSuffix(text: string, suffix: string) { return text } -function hasContent(text: string | undefined, allowPureWhitespace: boolean): boolean { - let refinedText = text ?? "" +function hasContent( + text: string | undefined, + allowPureWhitespace: boolean +): boolean { + let refinedText = text ?? '' if (!allowPureWhitespace) { refinedText = refinedText.trim() } return refinedText.length > 0 } -