restore passing baseUrl where appropriate

This commit is contained in:
John Wesley Walker III 2024-10-16 17:35:40 +00:00
parent df4b58c789
commit 2f42443dda
3 changed files with 39 additions and 15 deletions

46
dist/index.js vendored
View File

@ -1617,7 +1617,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
core.info('Retrieving the default branch name'); core.info('Retrieving the default branch name');
const octokit = github.getOctokit(authToken, { const octokit = github.getOctokit(authToken, {
baseUrl: (0, url_helper_1.getServerApiUrl)() baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
}); });
let result; let result;
try { try {
@ -1650,7 +1650,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) { function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = github.getOctokit(authToken, { const octokit = github.getOctokit(authToken, {
baseUrl: (0, url_helper_1.getServerApiUrl)() baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
}); });
const download = IS_WINDOWS const download = IS_WINDOWS
? octokit.rest.repos.downloadZipballArchive ? octokit.rest.repos.downloadZipballArchive
@ -2128,7 +2128,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
var _a; var _a;
try { try {
// GHES? // GHES?
if ((0, url_helper_1.isGhes)()) { if ((0, url_helper_1.isGhes)(baseUrl)) {
return; return;
} }
// Auth token? // Auth token?
@ -2174,7 +2174,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
if (actualHeadSha !== expectedHeadSha) { if (actualHeadSha !== expectedHeadSha) {
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`); core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
const octokit = github.getOctokit(token, { 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})` 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({ yield octokit.rest.repos.get({
@ -2454,22 +2454,46 @@ 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, false)) {
: process.env['GITHUB_SERVER_URL'] || 'https://github.com'; resolvedUrl = url;
return new url_1.URL(urlValue); }
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'; return process.env['GITHUB_API_URL'] || 'https://api.github.com';
} }
function isGhes() { function isGhes(url) {
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); const ghUrl = new url_1.URL(url || process.env['GITHUB_SERVER_URL'] || 'https://github.com');
const hostname = ghUrl.hostname.trimEnd().toUpperCase(); const hostname = ghUrl.hostname.trimEnd().toUpperCase();
const isGitHubHost = hostname === 'GITHUB.COM'; const isGitHubHost = hostname === 'GITHUB.COM';
const isGheHost = hostname.endsWith('.GHE.COM'); const isGheHost = hostname.endsWith('.GHE.COM');
const isLocalHost = hostname.endsWith('.LOCALHOST'); const isLocalHost = hostname.endsWith('.LOCALHOST');
return !isGitHubHost && !isGheHost && !isLocalHost; 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;
}
/***/ }), /***/ }),

View File

@ -88,7 +88,7 @@ export async function getDefaultBranch(
return await retryHelper.execute(async () => { return await retryHelper.execute(async () => {
core.info('Retrieving the default branch name') core.info('Retrieving the default branch name')
const octokit = github.getOctokit(authToken, { const octokit = github.getOctokit(authToken, {
baseUrl: getServerApiUrl() baseUrl: getServerApiUrl(baseUrl)
}) })
let result: string let result: string
try { try {
@ -131,7 +131,7 @@ async function downloadArchive(
baseUrl?: string baseUrl?: string
): Promise<Buffer> { ): Promise<Buffer> {
const octokit = github.getOctokit(authToken, { const octokit = github.getOctokit(authToken, {
baseUrl: getServerApiUrl() baseUrl: getServerApiUrl(baseUrl)
}) })
const download = IS_WINDOWS const download = IS_WINDOWS
? octokit.rest.repos.downloadZipballArchive ? octokit.rest.repos.downloadZipballArchive

View File

@ -192,7 +192,7 @@ export async function checkCommitInfo(
): Promise<void> { ): Promise<void> {
try { try {
// GHES? // GHES?
if (isGhes()) { if (isGhes(baseUrl)) {
return return
} }
@ -249,7 +249,7 @@ export async function checkCommitInfo(
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}` `Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
) )
const octokit = github.getOctokit(token, { 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( userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
'number' 'number'
)};run_id=${ )};run_id=${