Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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;
}


Expand Down
4 changes: 2 additions & 2 deletions src/github-api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ref-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export async function checkCommitInfo(
): Promise<void> {
try {
// GHES?
if (isGhes(baseUrl)) {
if (isGhes()) {
return
}

Expand Down Expand Up @@ -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=${
Expand Down
24 changes: 12 additions & 12 deletions src/url-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

return apiUrl
export function getServerApiUrl(): string {
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
}

export function isGhes(url?: string): boolean {
const ghUrl = getServerUrl(url)
export function isGhes(): boolean {
const ghUrl = new 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 ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
return !isGitHubHost && !isGheHost && !isLocalHost
}