mirror of
https://github.com/actions/checkout.git
synced 2024-12-26 11:03:04 +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* () {
|
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)
|
baseUrl: (0, url_helper_1.getServerApiUrl)()
|
||||||
});
|
});
|
||||||
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)
|
baseUrl: (0, url_helper_1.getServerApiUrl)()
|
||||||
});
|
});
|
||||||
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)(baseUrl)) {
|
if ((0, url_helper_1.isGhes)()) {
|
||||||
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),
|
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})`
|
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({
|
||||||
@ -2459,17 +2459,16 @@ function getServerUrl(url) {
|
|||||||
: process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
: process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||||
return new url_1.URL(urlValue);
|
return new url_1.URL(urlValue);
|
||||||
}
|
}
|
||||||
function getServerApiUrl(url) {
|
function getServerApiUrl() {
|
||||||
let apiUrl = 'https://api.github.com';
|
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
|
||||||
if (isGhes(url)) {
|
|
||||||
const serverUrl = getServerUrl(url);
|
|
||||||
apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString();
|
|
||||||
}
|
}
|
||||||
return apiUrl;
|
function isGhes() {
|
||||||
}
|
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||||
function isGhes(url) {
|
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||||
const ghUrl = getServerUrl(url);
|
const isGitHubHost = hostname === 'GITHUB.COM';
|
||||||
return ghUrl.hostname.toUpperCase() !== '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 () => {
|
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)
|
baseUrl: getServerApiUrl()
|
||||||
})
|
})
|
||||||
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)
|
baseUrl: getServerApiUrl()
|
||||||
})
|
})
|
||||||
const download = IS_WINDOWS
|
const download = IS_WINDOWS
|
||||||
? octokit.rest.repos.downloadZipballArchive
|
? octokit.rest.repos.downloadZipballArchive
|
||||||
|
@ -192,7 +192,7 @@ export async function checkCommitInfo(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// GHES?
|
// GHES?
|
||||||
if (isGhes(baseUrl)) {
|
if (isGhes()) {
|
||||||
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),
|
baseUrl: getServerApiUrl(),
|
||||||
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=${
|
||||||
|
@ -28,19 +28,19 @@ export function getServerUrl(url?: string): URL {
|
|||||||
return new URL(urlValue)
|
return new URL(urlValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getServerApiUrl(url?: string): string {
|
export function getServerApiUrl(): string {
|
||||||
let apiUrl = 'https://api.github.com'
|
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||||
|
|
||||||
if (isGhes(url)) {
|
|
||||||
const serverUrl = getServerUrl(url)
|
|
||||||
apiUrl = new URL(`${serverUrl.origin}/api/v3`).toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
||||||
const ghUrl = getServerUrl(url)
|
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