mirror of
https://gitea.com/actions/checkout.git
synced 2025-02-06 00:46:11 +08:00
Compare commits
No commits in common. "55f79d95dfa5db93171a58a2aef766066e6e65c2" and "041723abcc261fc3c9a738f026fe7e5fde461962" have entirely different histories.
55f79d95df
...
041723abcc
@ -1,28 +1,5 @@
|
||||
import * as urlHelper from '../src/url-helper'
|
||||
|
||||
describe('getServerUrl tests', () => {
|
||||
it('basics', async () => {
|
||||
// Note that URL::toString will append a trailing / when passed just a domain name ...
|
||||
expect(urlHelper.getServerUrl().toString()).toBe('https://github.com/')
|
||||
expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/')
|
||||
expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/')
|
||||
expect(urlHelper.getServerUrl('http://contoso.com').toString()).toBe(
|
||||
'http://contoso.com/'
|
||||
)
|
||||
expect(urlHelper.getServerUrl('https://contoso.com').toString()).toBe(
|
||||
'https://contoso.com/'
|
||||
)
|
||||
expect(urlHelper.getServerUrl('https://contoso.com/').toString()).toBe(
|
||||
'https://contoso.com/'
|
||||
)
|
||||
|
||||
// ... but can't make that same assumption when passed an URL that includes some deeper path.
|
||||
expect(urlHelper.getServerUrl('https://contoso.com/a/b').toString()).toBe(
|
||||
'https://contoso.com/a/b'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isGhes tests', () => {
|
||||
it('basics', async () => {
|
||||
expect(urlHelper.isGhes()).toBeFalsy()
|
||||
|
19
dist/index.js
vendored
19
dist/index.js
vendored
@ -2455,13 +2455,13 @@ function getFetchUrl(settings) {
|
||||
}
|
||||
function getServerUrl(url) {
|
||||
let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||
if (hasContent(url, false)) {
|
||||
resolvedUrl = url;
|
||||
}
|
||||
return new url_1.URL(resolvedUrl);
|
||||
}
|
||||
function getServerApiUrl(url) {
|
||||
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||
if (hasContent(url, false)) {
|
||||
let serverUrl = getServerUrl(url);
|
||||
if (isGhes(url)) {
|
||||
serverUrl.pathname = 'api/v3';
|
||||
@ -2477,24 +2477,19 @@ function isGhes(url) {
|
||||
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 isGheHost = hostname.endsWith('.GHE.COM');
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST');
|
||||
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
|
||||
return !isGitHubHost && !isGheHost && !isLocalHost;
|
||||
}
|
||||
function pruneSuffix(text, suffix) {
|
||||
if (hasContent(suffix, WhitespaceMode.Preserve) && (text === null || text === void 0 ? void 0 : text.endsWith(suffix))) {
|
||||
if (hasContent(suffix, true) && (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) {
|
||||
function hasContent(text, allowPureWhitespace) {
|
||||
let refinedText = text !== null && text !== void 0 ? text : '';
|
||||
if (whitespaceMode == WhitespaceMode.Trim) {
|
||||
if (!allowPureWhitespace) {
|
||||
refinedText = refinedText.trim();
|
||||
}
|
||||
return refinedText.length > 0;
|
||||
|
@ -22,7 +22,7 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
|
||||
|
||||
export function getServerUrl(url?: string): URL {
|
||||
let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||
if (hasContent(url, false)) {
|
||||
resolvedUrl = url!
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ export function getServerUrl(url?: string): URL {
|
||||
}
|
||||
|
||||
export function getServerApiUrl(url?: string): string {
|
||||
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||
if (hasContent(url, false)) {
|
||||
let serverUrl = getServerUrl(url)
|
||||
if (isGhes(url)) {
|
||||
serverUrl.pathname = 'api/v3'
|
||||
@ -51,30 +51,25 @@ export function isGhes(url?: string): boolean {
|
||||
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
||||
const isGitHubHost = hostname === 'GITHUB.COM'
|
||||
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM')
|
||||
const isGheHost = hostname.endsWith('.GHE.COM')
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST')
|
||||
|
||||
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost
|
||||
return !isGitHubHost && !isGheHost && !isLocalHost
|
||||
}
|
||||
|
||||
function pruneSuffix(text: string, suffix: string) {
|
||||
if (hasContent(suffix, WhitespaceMode.Preserve) && text?.endsWith(suffix)) {
|
||||
if (hasContent(suffix, true) && text?.endsWith(suffix)) {
|
||||
return text.substring(0, text.length - suffix.length)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
enum WhitespaceMode {
|
||||
Trim,
|
||||
Preserve
|
||||
}
|
||||
|
||||
function hasContent(
|
||||
text: string | undefined,
|
||||
whitespaceMode: WhitespaceMode
|
||||
allowPureWhitespace: boolean
|
||||
): boolean {
|
||||
let refinedText = text ?? ''
|
||||
if (whitespaceMode == WhitespaceMode.Trim) {
|
||||
if (!allowPureWhitespace) {
|
||||
refinedText = refinedText.trim()
|
||||
}
|
||||
return refinedText.length > 0
|
||||
|
Loading…
Reference in New Issue
Block a user