github: use isGhes func from actions/artifact module

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-07-15 13:14:08 +02:00
parent 4c7e849bb4
commit 99e6b01d39
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
2 changed files with 4 additions and 27 deletions

View File

@ -85,28 +85,6 @@ describe('apiURL', () => {
}); });
}); });
describe('isGHES', () => {
afterEach(() => {
process.env.GITHUB_SERVER_URL = '';
});
it('should return false when the request domain is github.com', () => {
process.env.GITHUB_SERVER_URL = 'https://github.com';
expect(GitHub.isGHES).toBe(false);
});
it('should return false when the request domain ends with ghe.com', () => {
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.com';
expect(GitHub.isGHES).toBe(false);
});
it('should return false when the request domain ends with ghe.localhost', () => {
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost';
expect(GitHub.isGHES).toBe(false);
});
it('should return true when the request domain is specific to an enterprise', () => {
process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com';
expect(GitHub.isGHES).toBe(true);
});
});
describe('repository', () => { describe('repository', () => {
it('returns GitHub repository', async () => { it('returns GitHub repository', async () => {
expect(GitHub.repository).toEqual('docker/actions-toolkit'); expect(GitHub.repository).toEqual('docker/actions-toolkit');

View File

@ -22,6 +22,7 @@ import os from 'os';
import path from 'path'; import path from 'path';
import {CreateArtifactRequest, FinalizeArtifactRequest, StringValue} from '@actions/artifact/lib/generated'; import {CreateArtifactRequest, FinalizeArtifactRequest, StringValue} from '@actions/artifact/lib/generated';
import {internalArtifactTwirpClient} from '@actions/artifact/lib/internal/shared/artifact-twirp-client'; import {internalArtifactTwirpClient} from '@actions/artifact/lib/internal/shared/artifact-twirp-client';
import {isGhes} from '@actions/artifact/lib/internal/shared/config';
import {getBackendIdsFromToken} from '@actions/artifact/lib/internal/shared/util'; import {getBackendIdsFromToken} from '@actions/artifact/lib/internal/shared/util';
import {getExpiration} from '@actions/artifact/lib/internal/upload/retention'; import {getExpiration} from '@actions/artifact/lib/internal/upload/retention';
import {InvalidResponseError, NetworkError} from '@actions/artifact'; import {InvalidResponseError, NetworkError} from '@actions/artifact';
@ -67,11 +68,9 @@ export class GitHub {
} }
static get isGHES(): boolean { static get isGHES(): boolean {
const serverURL = new URL(GitHub.serverURL); // FIXME: we are using the function from GitHub artifact module but should
const hostname = serverURL.hostname.trimEnd().toUpperCase(); // be within core module when available.
const isGitHubHost = hostname === 'GITHUB.COM'; return isGhes();
const isGHESHost = hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST');
return !isGitHubHost && !isGHESHost;
} }
static get repository(): string { static get repository(): string {