Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic push-status command implementation and extended push command #1321

Merged
merged 43 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a5f8148
feat: add basic bh push command implementation
roman-sainchuk Nov 8, 2023
5caf4a4
chore: unused option
roman-sainchuk Nov 8, 2023
ee4190e
fix: add config option
roman-sainchuk Nov 8, 2023
ce66354
chore: move cli related function out of the core
roman-sainchuk Nov 9, 2023
6a3fdb5
fix: preserve file structure
roman-sainchuk Nov 9, 2023
15eca35
fix: remove import from core
roman-sainchuk Nov 9, 2023
99f2c50
tests: cover bh ApiClient
roman-sainchuk Nov 9, 2023
43e2d7d
test: cover getApiKeys function
roman-sainchuk Nov 9, 2023
abfe9a1
tests: cover getDomain funtion
roman-sainchuk Nov 9, 2023
55e272a
tests: cover push command
roman-sainchuk Nov 10, 2023
d554354
chore: run prettier
roman-sainchuk Nov 10, 2023
233cbc3
fix: import isNotEmptyObject from core
roman-sainchuk Nov 17, 2023
1b30ccd
feat: add push-status command
SmoliyY Nov 30, 2023
c8eeec6
feat: add push-status command
SmoliyY Dec 7, 2023
523c070
fix: run prettier
SmoliyY Dec 7, 2023
526fe13
chore: revert package-lock
SmoliyY Dec 7, 2023
0c429fa
chore: update package-lock
SmoliyY Dec 7, 2023
5e57af6
fix: prettier
SmoliyY Dec 7, 2023
384ef09
feat: add isMaibBranch flag
SmoliyY Dec 11, 2023
30942d2
chore: update according to the new api
roman-sainchuk Dec 14, 2023
ef66dd6
chore: add verbose flag for push command
SmoliyY Dec 15, 2023
9f72bae
chore: update types
roman-sainchuk Dec 15, 2023
68e9eb2
fix: output of push id for push command
SmoliyY Dec 15, 2023
a394e97
chore: add mising form data
SmoliyY Dec 15, 2023
bbb5ace
chore: add mising form data
SmoliyY Dec 15, 2023
454787f
Merge branch 'main' into feat/bh-push-command
IgorKarpiuk Jan 9, 2024
6911636
refactor: update push command
IgorKarpiuk Jan 9, 2024
13f27d8
feat: update push-status command
IgorKarpiuk Jan 19, 2024
c38b227
Merge branch 'main' into feat/bh-push-command
RomanHotsiy Jan 19, 2024
2011f40
fix: fix spinner test
IgorKarpiuk Jan 19, 2024
36c082e
fix: resolve conflicts
IgorKarpiuk Jan 19, 2024
c7749bf
fix: use kebab case for options
IgorKarpiuk Jan 22, 2024
273ae1e
chore: update messages
IgorKarpiuk Jan 23, 2024
53d24fe
chore: move api client to cli package
IgorKarpiuk Jan 24, 2024
68e2f03
chore: move form data package
IgorKarpiuk Jan 24, 2024
e201ccc
chore: remove comments and adjust imports
IgorKarpiuk Jan 24, 2024
4a3944c
chore: update folder structure
IgorKarpiuk Jan 24, 2024
d0cc8a5
Merge branch 'main' into feat/bh-push-command
IgorKarpiuk Jan 24, 2024
87c6dcc
fix: remove config from options
IgorKarpiuk Jan 25, 2024
306622e
Merge branch 'main' into feat/bh-push-command
IgorKarpiuk Jan 25, 2024
aa98075
fix: update score card url field
IgorKarpiuk Jan 25, 2024
98675a3
chore: add change set
IgorKarpiuk Jan 26, 2024
7a85e28
fix: update command description
IgorKarpiuk Jan 26, 2024
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
58 changes: 14 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@types/react": "^17.0.0 || ^18.2.21",
"@types/react-dom": "^17.0.0 || ^18.2.7",
"@types/semver": "^7.5.0",
"@types/yargs": "17.0.5",
"@types/yargs": "17.0.32",
"typescript": "^5.2.2"
}
}
37 changes: 37 additions & 0 deletions packages/cli/src/cms/__tests__/api-keys.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { getApiKeys } from '../api-keys';
import * as fs from 'fs';

describe('getApiKeys()', () => {
afterEach(() => {
jest.resetAllMocks();
});

it('should return api key from environment variable', () => {
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';

expect(getApiKeys('test-domain')).toEqual('test-api-key');
});

it('should return api key from credentials file', () => {
process.env.REDOCLY_AUTHORIZATION = '';

jest.spyOn(fs, 'existsSync').mockReturnValue(true);
jest.spyOn(fs, 'readFileSync').mockReturnValue(
JSON.stringify({
['test-domain']: 'test-api-key-from-credentials-file',
})
);

expect(getApiKeys('test-domain')).toEqual('test-api-key-from-credentials-file');
});

it('should throw an error if no api key provided', () => {
process.env.REDOCLY_AUTHORIZATION = '';

jest.spyOn(fs, 'existsSync').mockReturnValue(false);

expect(() => getApiKeys('test-domain')).toThrowError(
'No api key provided, please use environment variable REDOCLY_DOMAIN.'
);
});
});
15 changes: 15 additions & 0 deletions packages/cli/src/cms/__tests__/domains.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getDomain } from '../domains';

describe('getDomain()', () => {
it('should return the domain from environment variable', () => {
process.env.REDOCLY_DOMAIN = 'test-domain';

expect(getDomain()).toBe('test-domain');
});

it('should return the default domain if no domain provided', () => {
process.env.REDOCLY_DOMAIN = '';

expect(getDomain()).toBe('https://app.beta.redocly.com');
});
});
27 changes: 27 additions & 0 deletions packages/cli/src/cms/api-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { resolve } from 'path';
import { homedir } from 'os';
import { existsSync, readFileSync } from 'fs';
import { isNotEmptyObject } from '@redocly/openapi-core/lib/utils';

const TOKEN_FILENAME = '.redocly-config.json';
IgorKarpiuk marked this conversation as resolved.
Show resolved Hide resolved

function readCredentialsFile(credentialsPath: string) {
return existsSync(credentialsPath) ? JSON.parse(readFileSync(credentialsPath, 'utf-8')) : {};
}

export function getApiKeys(domain: string) {
const apiKey = process.env.REDOCLY_AUTHORIZATION;

if (apiKey) {
return apiKey;
}

const credentialsPath = resolve(homedir(), TOKEN_FILENAME);
const credentials = readCredentialsFile(credentialsPath);

if (isNotEmptyObject(credentials) && credentials[domain]) {
return credentials[domain];
}

throw new Error('No api key provided, please use environment variable REDOCLY_DOMAIN.');
}
68 changes: 68 additions & 0 deletions packages/cli/src/cms/commands/__tests__/push-status.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { handlePushStatus } from '../push-status';
import { PushStatusResponse } from '@redocly/openapi-core';

const remotes = {
getPushStatus: jest.fn(),
getRemotesList: jest.fn(),
};

jest.mock('@redocly/openapi-core', () => ({
...jest.requireActual('@redocly/openapi-core'),
BlueHarvestApiClient: jest.fn().mockImplementation(function (this: any, ...args) {
IgorKarpiuk marked this conversation as resolved.
Show resolved Hide resolved
this.remotes = remotes;
}),
}));

// describe('handlePushStatus()', () => {
// const pushResponseStub: PushStatusResponse = {
// buildUrlLogs: 'https://test-build-url-logs',
// deploymentStatus: 'SUCCEEDED',
// scorecard: [],
// status: 'SUCCEEDED',
// url: 'https://test-url',
// };

// beforeEach(() => {
// remotes.getRemotesList.mockResolvedValueOnce({ items: [{ id: 'test-remote-id' }] });

// remotes.getPushStatus.mockResolvedValueOnce(pushResponseStub);

// jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
// jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
// });

// it('should return success push status', async () => {
// const mockConfig = { apis: {} } as any;
// process.env.REDOCLY_AUTHORIZATION = 'test-api-key';

// await handlePushStatus(
// {
// domain: 'test-domain',
// mountPath: 'test-mount-path',
// organization: 'test-org',
// project: 'test-project',
// pushId: 'test-push-id',
// format: 'json',
// },
// mockConfig
// );

// expect(remotes.getRemotesList).toHaveBeenCalledWith(
// 'test-org',
// 'test-project',
// 'test-mount-path'
// );
// expect(process.stderr.write).toHaveBeenCalledTimes(2);
// expect(process.stdout.write).toHaveBeenCalledWith(
// JSON.stringify(
// {
// status: 'Success',
// buildUrlLogs: 'https://test-build-url-logs',
// url: 'https://test-url',
// },
// null,
// 2
// )
// );
// });
// });
Loading
Loading