mirror of http://gitea.com/actions/checkout
Compare commits
2 Commits
981bf88c6a
...
777b9d8d9b
Author | SHA1 | Date |
---|---|---|
dependabot[bot] | 777b9d8d9b | |
John Wesley Walker III | 163217dfcd |
|
@ -0,0 +1,55 @@
|
||||||
|
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()
|
||||||
|
expect(urlHelper.isGhes('https://github.com')).toBeFalsy()
|
||||||
|
expect(urlHelper.isGhes('https://contoso.ghe.com')).toBeFalsy()
|
||||||
|
expect(urlHelper.isGhes('https://test.github.localhost')).toBeFalsy()
|
||||||
|
expect(urlHelper.isGhes('https://src.onpremise.fabrikam.com')).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
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://contoso.ghe.com')).toBe(
|
||||||
|
'https://api.contoso.ghe.com'
|
||||||
|
)
|
||||||
|
expect(urlHelper.getServerApiUrl('https://fabrikam.GHE.COM')).toBe(
|
||||||
|
'https://api.fabrikam.ghe.com'
|
||||||
|
)
|
||||||
|
expect(
|
||||||
|
urlHelper.getServerApiUrl('https://src.onpremise.fabrikam.com')
|
||||||
|
).toBe('https://src.onpremise.fabrikam.com/api/v3')
|
||||||
|
})
|
||||||
|
})
|
|
@ -2454,22 +2454,50 @@ function getFetchUrl(settings) {
|
||||||
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
|
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
|
||||||
}
|
}
|
||||||
function getServerUrl(url) {
|
function getServerUrl(url) {
|
||||||
let urlValue = url && url.trim().length > 0
|
let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||||
? url
|
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||||
: process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
resolvedUrl = url;
|
||||||
return new url_1.URL(urlValue);
|
}
|
||||||
|
return new url_1.URL(resolvedUrl);
|
||||||
}
|
}
|
||||||
function getServerApiUrl(url) {
|
function getServerApiUrl(url) {
|
||||||
let apiUrl = 'https://api.github.com';
|
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||||
if (isGhes(url)) {
|
let serverUrl = getServerUrl(url);
|
||||||
const serverUrl = getServerUrl(url);
|
if (isGhes(url)) {
|
||||||
apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString();
|
serverUrl.pathname = 'api/v3';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
serverUrl.hostname = 'api.' + serverUrl.hostname;
|
||||||
|
}
|
||||||
|
return pruneSuffix(serverUrl.toString(), '/');
|
||||||
}
|
}
|
||||||
return apiUrl;
|
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
|
||||||
}
|
}
|
||||||
function isGhes(url) {
|
function isGhes(url) {
|
||||||
const ghUrl = getServerUrl(url);
|
const ghUrl = new url_1.URL(url || process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||||
|
const isGitHubHost = hostname === 'GITHUB.COM';
|
||||||
|
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
|
||||||
|
const isLocalHost = hostname.endsWith('.LOCALHOST');
|
||||||
|
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
|
||||||
|
}
|
||||||
|
function pruneSuffix(text, suffix) {
|
||||||
|
if (hasContent(suffix, WhitespaceMode.Preserve) && (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) {
|
||||||
|
let refinedText = text !== null && text !== void 0 ? text : '';
|
||||||
|
if (whitespaceMode == WhitespaceMode.Trim) {
|
||||||
|
refinedText = refinedText.trim();
|
||||||
|
}
|
||||||
|
return refinedText.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"version": "4.2.1",
|
"version": "4.2.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^6.0.0",
|
"@actions/github": "^6.0.0",
|
||||||
"@actions/io": "^1.1.3",
|
"@actions/io": "^1.1.3",
|
||||||
|
@ -17,21 +17,21 @@
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.13",
|
||||||
"@types/node": "^20.12.12",
|
"@types/node": "^20.12.12",
|
||||||
"@types/uuid": "^9.0.8",
|
"@types/uuid": "^9.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
||||||
"@typescript-eslint/parser": "^7.9.0",
|
"@typescript-eslint/parser": "^7.9.0",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-github": "^4.10.2",
|
"eslint-plugin-github": "^4.10.2",
|
||||||
"eslint-plugin-jest": "^28.8.2",
|
"eslint-plugin-jest": "^28.8.3",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-circus": "^29.7.0",
|
"jest-circus": "^29.7.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.2.5",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.6.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@aashutoshrathi/word-wrap": {
|
"node_modules/@aashutoshrathi/word-wrap": {
|
||||||
|
@ -44,20 +44,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "1.10.1",
|
"version": "1.11.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz",
|
||||||
"integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==",
|
"integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"uuid": "^8.3.2"
|
"@actions/http-client": "^2.0.1"
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@actions/core/node_modules/uuid": {
|
|
||||||
"version": "8.3.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
|
||||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
|
||||||
"bin": {
|
|
||||||
"uuid": "dist/bin/uuid"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/exec": {
|
"node_modules/@actions/exec": {
|
||||||
|
@ -1572,9 +1564,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/jest": {
|
"node_modules/@types/jest": {
|
||||||
"version": "29.5.12",
|
"version": "29.5.13",
|
||||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.12.tgz",
|
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz",
|
||||||
"integrity": "sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==",
|
"integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"expect": "^29.0.0",
|
"expect": "^29.0.0",
|
||||||
|
@ -1827,9 +1819,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@vercel/ncc": {
|
"node_modules/@vercel/ncc": {
|
||||||
"version": "0.38.1",
|
"version": "0.38.2",
|
||||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz",
|
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.2.tgz",
|
||||||
"integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==",
|
"integrity": "sha512-3yel3jaxUg9pHBv4+KeC9qlbdZPug+UMtUOlhvpDYCMSgcNSrS2Hv1LoqMsOV7hf2lYscx+BESfJOIla1WsmMQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"ncc": "dist/ncc/cli.js"
|
"ncc": "dist/ncc/cli.js"
|
||||||
|
@ -3218,9 +3210,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-jest": {
|
"node_modules/eslint-plugin-jest": {
|
||||||
"version": "28.8.2",
|
"version": "28.8.3",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.3.tgz",
|
||||||
"integrity": "sha512-mC3OyklHmS5i7wYU1rGId9EnxRI8TVlnFG56AE+8U9iRy6zwaNygZR+DsdZuCL0gRG0wVeyzq+uWcPt6yJrrMA==",
|
"integrity": "sha512-HIQ3t9hASLKm2IhIOqnu+ifw7uLZkIlR7RYNv7fMcEi/p0CIiJmfriStQS2LDkgtY4nyLbIZAD+JL347Yc2ETQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
"@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
||||||
|
@ -6902,9 +6894,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.5.4",
|
"version": "5.6.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
|
||||||
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
|
"integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
|
|
10
package.json
10
package.json
|
@ -28,7 +28,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/actions/checkout#readme",
|
"homepage": "https://github.com/actions/checkout#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^6.0.0",
|
"@actions/github": "^6.0.0",
|
||||||
"@actions/io": "^1.1.3",
|
"@actions/io": "^1.1.3",
|
||||||
|
@ -36,20 +36,20 @@
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.13",
|
||||||
"@types/node": "^20.12.12",
|
"@types/node": "^20.12.12",
|
||||||
"@types/uuid": "^9.0.8",
|
"@types/uuid": "^9.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
||||||
"@typescript-eslint/parser": "^7.9.0",
|
"@typescript-eslint/parser": "^7.9.0",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-github": "^4.10.2",
|
"eslint-plugin-github": "^4.10.2",
|
||||||
"eslint-plugin-jest": "^28.8.2",
|
"eslint-plugin-jest": "^28.8.3",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-circus": "^29.7.0",
|
"jest-circus": "^29.7.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.2.5",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,26 +21,61 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getServerUrl(url?: string): URL {
|
export function getServerUrl(url?: string): URL {
|
||||||
let urlValue =
|
let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
url && url.trim().length > 0
|
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||||
? url
|
resolvedUrl = url!
|
||||||
: process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
}
|
||||||
return new URL(urlValue)
|
|
||||||
|
return new URL(resolvedUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getServerApiUrl(url?: string): string {
|
export function getServerApiUrl(url?: string): string {
|
||||||
let apiUrl = 'https://api.github.com'
|
if (hasContent(url, WhitespaceMode.Trim)) {
|
||||||
|
let serverUrl = getServerUrl(url)
|
||||||
|
if (isGhes(url)) {
|
||||||
|
serverUrl.pathname = 'api/v3'
|
||||||
|
} else {
|
||||||
|
serverUrl.hostname = 'api.' + serverUrl.hostname
|
||||||
|
}
|
||||||
|
|
||||||
if (isGhes(url)) {
|
return pruneSuffix(serverUrl.toString(), '/')
|
||||||
const serverUrl = getServerUrl(url)
|
|
||||||
apiUrl = new URL(`${serverUrl.origin}/api/v3`).toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiUrl
|
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isGhes(url?: string): boolean {
|
export function isGhes(url?: string): boolean {
|
||||||
const ghUrl = getServerUrl(url)
|
const ghUrl = new URL(
|
||||||
|
url || process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
|
)
|
||||||
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
||||||
|
const isGitHubHost = hostname === 'GITHUB.COM'
|
||||||
|
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM')
|
||||||
|
const isLocalHost = hostname.endsWith('.LOCALHOST')
|
||||||
|
|
||||||
|
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost
|
||||||
|
}
|
||||||
|
|
||||||
|
function pruneSuffix(text: string, suffix: string) {
|
||||||
|
if (hasContent(suffix, WhitespaceMode.Preserve) && text?.endsWith(suffix)) {
|
||||||
|
return text.substring(0, text.length - suffix.length)
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
enum WhitespaceMode {
|
||||||
|
Trim,
|
||||||
|
Preserve
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasContent(
|
||||||
|
text: string | undefined,
|
||||||
|
whitespaceMode: WhitespaceMode
|
||||||
|
): boolean {
|
||||||
|
let refinedText = text ?? ''
|
||||||
|
if (whitespaceMode == WhitespaceMode.Trim) {
|
||||||
|
refinedText = refinedText.trim()
|
||||||
|
}
|
||||||
|
return refinedText.length > 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue