mirror of
https://github.com/actions/checkout.git
synced 2024-12-25 18:43:05 +07:00
utl-helper.ts
now leverages well-known environment variables.
This commit is contained in:
parent
eef61447b9
commit
e8e821983d
27
dist/index.js
vendored
27
dist/index.js
vendored
@ -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();
|
||||
function getServerApiUrl() {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
|
||||
}
|
||||
return apiUrl;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
baseUrl: getServerApiUrl()
|
||||
})
|
||||
let result: string
|
||||
try {
|
||||
@ -131,7 +131,7 @@ async function downloadArchive(
|
||||
baseUrl?: string
|
||||
): Promise<Buffer> {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: getServerApiUrl(baseUrl)
|
||||
baseUrl: getServerApiUrl()
|
||||
})
|
||||
const download = IS_WINDOWS
|
||||
? octokit.rest.repos.downloadZipballArchive
|
||||
|
@ -192,7 +192,7 @@ export async function checkCommitInfo(
|
||||
): Promise<void> {
|
||||
try {
|
||||
// GHES?
|
||||
if (isGhes(baseUrl)) {
|
||||
if (isGhes()) {
|
||||
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),
|
||||
baseUrl: getServerApiUrl(),
|
||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
||||
'number'
|
||||
)};run_id=${
|
||||
|
@ -28,19 +28,19 @@ export function getServerUrl(url?: string): URL {
|
||||
return new URL(urlValue)
|
||||
}
|
||||
|
||||
export function getServerApiUrl(url?: string): string {
|
||||
let apiUrl = 'https://api.github.com'
|
||||
|
||||
if (isGhes(url)) {
|
||||
const serverUrl = getServerUrl(url)
|
||||
apiUrl = new URL(`${serverUrl.origin}/api/v3`).toString()
|
||||
export function getServerApiUrl(): string {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||
}
|
||||
|
||||
return apiUrl
|
||||
}
|
||||
export function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
)
|
||||
|
||||
export function isGhes(url?: string): boolean {
|
||||
const ghUrl = getServerUrl(url)
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
||||
const isGitHubHost = hostname === 'GITHUB.COM'
|
||||
const isGheHost = hostname.endsWith('.GHE.COM')
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST')
|
||||
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
||||
return !isGitHubHost && !isGheHost && !isLocalHost
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user