3
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2025-04-24 12:25:34 +00:00

utl-helper.ts now leverages well-known environment variables.

This commit is contained in:
John Wesley Walker III 2024-10-11 15:31:54 +00:00
parent eef61447b9
commit e8e821983d
4 changed files with 29 additions and 30 deletions

27
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* () {
core.info('Retrieving the default branch name');
const octokit = github.getOctokit(authToken, {
baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
baseUrl: (0, url_helper_1.getServerApiUrl)()
});
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)
baseUrl: (0, url_helper_1.getServerApiUrl)()
});
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)(baseUrl)) {
if ((0, url_helper_1.isGhes)()) {
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),
baseUrl: (0, url_helper_1.getServerApiUrl)(),
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({
@ -2459,17 +2459,16 @@ function getServerUrl(url) {
: process.env['GITHUB_SERVER_URL'] || 'https://github.com';
return new url_1.URL(urlValue);
}
function getServerApiUrl(url) {
let apiUrl = 'https://api.github.com';
if (isGhes(url)) {
const serverUrl = getServerUrl(url);
apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString();
}
return apiUrl;
function getServerApiUrl() {
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
}
function isGhes(url) {
const ghUrl = getServerUrl(url);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
function isGhes() {
const ghUrl = new url_1.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;
}