mirror of http://gitea.com/actions/checkout
Compare commits
6 Commits
e8e821983d
...
041723abcc
Author | SHA1 | Date |
---|---|---|
John Wesley Walker III | 041723abcc | |
John Wesley Walker III | 813c3f2d82 | |
John Wesley Walker III | 19060a122d | |
John Wesley Walker III | 7fcbcdce7d | |
John Wesley Walker III | 2f42443dda | |
John Wesley Walker III | df4b58c789 |
|
@ -0,0 +1,32 @@
|
|||
import * as urlHelper from '../src/url-helper'
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
|
@ -1617,7 +1617,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
|
|||
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
||||
core.info('Retrieving the default branch name');
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)()
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
|
||||
});
|
||||
let result;
|
||||
try {
|
||||
|
@ -1650,7 +1650,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
|
|||
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)()
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
|
||||
});
|
||||
const download = IS_WINDOWS
|
||||
? octokit.rest.repos.downloadZipballArchive
|
||||
|
@ -2128,7 +2128,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
|
|||
var _a;
|
||||
try {
|
||||
// GHES?
|
||||
if ((0, url_helper_1.isGhes)()) {
|
||||
if ((0, url_helper_1.isGhes)(baseUrl)) {
|
||||
return;
|
||||
}
|
||||
// Auth token?
|
||||
|
@ -2174,7 +2174,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
|
|||
if (actualHeadSha !== expectedHeadSha) {
|
||||
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
|
||||
const octokit = github.getOctokit(token, {
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)(),
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl),
|
||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload('number')};run_id=${process.env['GITHUB_RUN_ID']};expected_head_sha=${expectedHeadSha};actual_head_sha=${actualHeadSha})`
|
||||
});
|
||||
yield octokit.rest.repos.get({
|
||||
|
@ -2454,22 +2454,46 @@ function getFetchUrl(settings) {
|
|||
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
|
||||
}
|
||||
function getServerUrl(url) {
|
||||
let urlValue = url && url.trim().length > 0
|
||||
? url
|
||||
: process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||
return new url_1.URL(urlValue);
|
||||
let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||
if (hasContent(url, false)) {
|
||||
resolvedUrl = url;
|
||||
}
|
||||
return new url_1.URL(resolvedUrl);
|
||||
}
|
||||
function getServerApiUrl() {
|
||||
function getServerApiUrl(url) {
|
||||
if (hasContent(url, false)) {
|
||||
let serverUrl = getServerUrl(url);
|
||||
if (isGhes(url)) {
|
||||
serverUrl.pathname = 'api/v3';
|
||||
}
|
||||
else {
|
||||
serverUrl.hostname = 'api.' + serverUrl.hostname;
|
||||
}
|
||||
return pruneSuffix(serverUrl.toString(), '/');
|
||||
}
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
|
||||
}
|
||||
function isGhes() {
|
||||
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
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 isGheHost = hostname.endsWith('.GHE.COM');
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST');
|
||||
return !isGitHubHost && !isGheHost && !isLocalHost;
|
||||
}
|
||||
function pruneSuffix(text, 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;
|
||||
}
|
||||
function hasContent(text, allowPureWhitespace) {
|
||||
let refinedText = text !== null && text !== void 0 ? text : '';
|
||||
if (!allowPureWhitespace) {
|
||||
refinedText = refinedText.trim();
|
||||
}
|
||||
return refinedText.length > 0;
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -88,7 +88,7 @@ export async function getDefaultBranch(
|
|||
return await retryHelper.execute(async () => {
|
||||
core.info('Retrieving the default branch name')
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: getServerApiUrl()
|
||||
baseUrl: getServerApiUrl(baseUrl)
|
||||
})
|
||||
let result: string
|
||||
try {
|
||||
|
@ -131,7 +131,7 @@ async function downloadArchive(
|
|||
baseUrl?: string
|
||||
): Promise<Buffer> {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: getServerApiUrl()
|
||||
baseUrl: getServerApiUrl(baseUrl)
|
||||
})
|
||||
const download = IS_WINDOWS
|
||||
? octokit.rest.repos.downloadZipballArchive
|
||||
|
|
|
@ -192,7 +192,7 @@ export async function checkCommitInfo(
|
|||
): Promise<void> {
|
||||
try {
|
||||
// GHES?
|
||||
if (isGhes()) {
|
||||
if (isGhes(baseUrl)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ export async function checkCommitInfo(
|
|||
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
|
||||
)
|
||||
const octokit = github.getOctokit(token, {
|
||||
baseUrl: getServerApiUrl(),
|
||||
baseUrl: getServerApiUrl(baseUrl),
|
||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
||||
'number'
|
||||
)};run_id=${
|
||||
|
|
|
@ -21,20 +21,32 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
|
|||
}
|
||||
|
||||
export function getServerUrl(url?: string): URL {
|
||||
let urlValue =
|
||||
url && url.trim().length > 0
|
||||
? url
|
||||
: process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
return new URL(urlValue)
|
||||
let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
if (hasContent(url, false)) {
|
||||
resolvedUrl = url!
|
||||
}
|
||||
|
||||
return new URL(resolvedUrl)
|
||||
}
|
||||
|
||||
export function getServerApiUrl(): string {
|
||||
export function getServerApiUrl(url?: string): string {
|
||||
if (hasContent(url, false)) {
|
||||
let serverUrl = getServerUrl(url)
|
||||
if (isGhes(url)) {
|
||||
serverUrl.pathname = 'api/v3'
|
||||
} else {
|
||||
serverUrl.hostname = 'api.' + serverUrl.hostname
|
||||
}
|
||||
|
||||
return pruneSuffix(serverUrl.toString(), '/')
|
||||
}
|
||||
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||
}
|
||||
|
||||
export function isGhes(): boolean {
|
||||
export function isGhes(url?: string): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
url || process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
)
|
||||
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
||||
|
@ -44,3 +56,21 @@ export function isGhes(): 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)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
function hasContent(
|
||||
text: string | undefined,
|
||||
allowPureWhitespace: boolean
|
||||
): boolean {
|
||||
let refinedText = text ?? ''
|
||||
if (!allowPureWhitespace) {
|
||||
refinedText = refinedText.trim()
|
||||
}
|
||||
return refinedText.length > 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue