Skip to content

Commit

Permalink
github: use isGhes func from actions/artifact module
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jul 15, 2024
1 parent 4c7e849 commit 99e6b01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
22 changes: 0 additions & 22 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
it('returns GitHub repository', async () => {
expect(GitHub.repository).toEqual('docker/actions-toolkit');
Expand Down
9 changes: 4 additions & 5 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import os from 'os';
import path from 'path';
import {CreateArtifactRequest, FinalizeArtifactRequest, StringValue} from '@actions/artifact/lib/generated';
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 {getExpiration} from '@actions/artifact/lib/internal/upload/retention';
import {InvalidResponseError, NetworkError} from '@actions/artifact';
Expand Down Expand Up @@ -67,11 +68,9 @@ export class GitHub {
}

static get isGHES(): boolean {
const serverURL = new URL(GitHub.serverURL);
const hostname = serverURL.hostname.trimEnd().toUpperCase();
const isGitHubHost = hostname === 'GITHUB.COM';
const isGHESHost = hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST');
return !isGitHubHost && !isGHESHost;
// FIXME: we are using the function from GitHub artifact module but should
// be within core module when available.
return isGhes();
}

static get repository(): string {
Expand Down

0 comments on commit 99e6b01

Please sign in to comment.