github: add serverURL annd provenanceBuilderID

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-25 03:20:18 +01:00
parent 380149da27
commit b03f6a405c
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
3 changed files with 48 additions and 3 deletions

View file

@ -1,10 +1,11 @@
import {describe, expect, jest, it, beforeEach} from '@jest/globals';
import {Context} from '@actions/github/lib/context';
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
import {Context} from '@actions/github/lib/context';
import {GitHub, Payload, ReposGetResponseData} from '../src/github';
beforeEach(() => {
jest.clearAllMocks();
GitHub.getInstance().reset();
});
jest.spyOn(GitHub.prototype, 'context').mockImplementation((): Context => {
@ -24,12 +25,39 @@ jest.spyOn(GitHub.prototype as any, 'ref').mockImplementation((): string => {
return 'refs/heads/master';
});
describe('serverURL', () => {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = {
...originalEnv,
GITHUB_SERVER_URL: 'https://foo.github.com'
};
});
afterEach(() => {
process.env = originalEnv;
});
it('returns default', async () => {
process.env.GITHUB_SERVER_URL = '';
expect(GitHub.getInstance().serverURL()).toEqual('https://github.com');
});
it('returns from env', async () => {
expect(GitHub.getInstance().serverURL()).toEqual('https://foo.github.com');
});
});
describe('gitContext', () => {
it('returns refs/heads/master', async () => {
expect(GitHub.getInstance().gitContext()).toEqual('https://github.com/docker/test-docker-action.git#refs/heads/master');
});
});
describe('provenanceBuilderID', () => {
it('returns 123', async () => {
expect(GitHub.getInstance().provenanceBuilderID()).toEqual('https://github.com/docker/test-docker-action/actions/runs/123');
});
});
describe('repo', () => {
it('returns GitHub repository', async () => {
const repo = await GitHub.getInstance().repo(process.env.GITHUB_TOKEN || '');