Compare commits

..

No commits in common. "19060a122d0c2f1ca421f732a370ce68d2fc33de" and "2f42443ddaaf0277464417de30a81183e5b91981" have entirely different histories.

3 changed files with 14 additions and 25 deletions

View File

@ -14,20 +14,10 @@ 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')
})
})

6
dist/index.js vendored
View File

@ -2464,10 +2464,10 @@ function getServerApiUrl(url) {
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(), '/');
}
@ -2488,7 +2488,7 @@ function pruneSuffix(text, suffix) {
return text;
}
function hasContent(text, allowPureWhitespace) {
let refinedText = text !== null && text !== void 0 ? text : '';
let refinedText = text !== null && text !== void 0 ? text : "";
if (!allowPureWhitespace) {
refinedText = refinedText.trim();
}

View File

@ -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,6 +57,7 @@ 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)
@ -64,13 +65,11 @@ 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
}