fix: support pathname except ssh

This commit is contained in:
CHANX 2023-04-27 23:17:17 +08:00 committed by Frank
parent 8530928916
commit 5f56636ef8
5 changed files with 27 additions and 12 deletions

View file

@ -16,17 +16,23 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
}
// "origin" is SCHEME://HOSTNAME[:PORT]
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
const baseURL = getBaseUrl(serviceUrl.href)
return `${baseURL}/${encodedOwner}/${encodedName}`
}
export function getServerUrl(url?: string): URL {
let urlValue =
const urlValue =
url && url.trim().length > 0
? url
: process.env['GITHUB_SERVER_URL'] || 'https://github.com'
return new URL(urlValue)
}
export function getBaseUrl(url: string): string {
const matcher = url.match(/^[^?]+/)
return (matcher && matcher[0].replace(/\/+$/g, '')) || ''
}
export function getServerApiUrl(url?: string): string {
let apiUrl = 'https://api.github.com'