Skip to content

Commit

Permalink
fix: resolve an issue with options in the push command (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorKarpiuk authored Feb 1, 2024
1 parent 4868a5b commit e61eb26
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-badgers-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/cli": patch
---

Fixed an issue with the `push` command, when `destination` option does not work without specifying it in `redocly.yaml`.
32 changes: 14 additions & 18 deletions packages/cli/src/__tests__/commands/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ describe('transformPush', () => {
const cb = jest.fn();
transformPush(cb)(
{
api: 'openapi.yaml',
maybeDestination: '@testing_org/main@v1',
apis: ['openapi.yaml', '@testing_org/main@v1'],
},
{} as any
);
Expand All @@ -300,9 +299,7 @@ describe('transformPush', () => {
const cb = jest.fn();
transformPush(cb)(
{
api: 'openapi.yaml',
maybeDestination: '@testing_org/main@v1',
maybeBranchName: 'other',
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
},
{} as any
);
Expand All @@ -319,9 +316,7 @@ describe('transformPush', () => {
const cb = jest.fn();
transformPush(cb)(
{
api: 'openapi.yaml',
maybeDestination: '@testing_org/main@v1',
maybeBranchName: 'other',
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
branch: 'priority-branch',
},
{} as any
Expand All @@ -339,13 +334,13 @@ describe('transformPush', () => {
const cb = jest.fn();
transformPush(cb)(
{
api: '@testing_org/main@v1',
apis: ['main@v1'],
},
{} as any
);
expect(cb).toBeCalledWith(
{
destination: '@testing_org/main@v1',
destination: 'main@v1',
},
{}
);
Expand All @@ -354,7 +349,7 @@ describe('transformPush', () => {
const cb = jest.fn();
transformPush(cb)(
{
api: 'test.yaml',
apis: ['test.yaml'],
},
{} as any
);
Expand All @@ -365,31 +360,32 @@ describe('transformPush', () => {
{}
);
});
it('should accept aliases for the old syntax', () => {

it('should use destination from option', () => {
const cb = jest.fn();
transformPush(cb)(
{
api: 'alias',
maybeDestination: '@testing_org/main@v1',
apis: ['test.yaml', 'test@v1'],
destination: 'main@v1',
},
{} as any
);
expect(cb).toBeCalledWith(
{
destination: '@testing_org/main@v1',
api: 'alias',
destination: 'main@v1',
api: 'test.yaml',
},
{}
);
});

it('should use --job-id option firstly', () => {
const cb = jest.fn();
transformPush(cb)(
{
'batch-id': 'b-123',
'job-id': 'j-123',
api: 'test',
maybeDestination: 'main@v1',
apis: ['test'],
branch: 'test',
destination: 'main@v1',
},
Expand Down
15 changes: 6 additions & 9 deletions packages/cli/src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function commonPushHandler({
if (project && mountPath) {
return handleCMSPush;
}
return handlePush;
return transformPush(handlePush);
}

export async function handlePush(argv: PushOptions, config: Config): Promise<void> {
Expand Down Expand Up @@ -354,8 +354,7 @@ export function getDestinationProps(
}

type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
maybeDestination?: string;
maybeBranchName?: string;
apis?: string[];
branch?: string;
destination?: string;
};
Expand All @@ -364,16 +363,16 @@ export const transformPush =
(callback: typeof handlePush) =>
(
{
api: maybeApiOrDestination,
maybeDestination,
maybeBranchName,
apis,
branch,
'batch-id': batchId,
'job-id': jobId,
...rest
}: BarePushArgs & { 'batch-id'?: string },
config: Config
) => {
const [maybeApiOrDestination, maybeDestination, maybeBranchName] = apis || [];

if (batchId) {
process.stderr.write(
yellow(
Expand Down Expand Up @@ -410,12 +409,10 @@ export const transformPush =
apiFile = maybeApiOrDestination;
}

destination = rest.destination || destination;

return callback(
{
...rest,
destination,
destination: rest.destination ?? destination,
api: apiFile,
branchName: branch ?? maybeBranchName,
'job-id': jobId || batchId,
Expand Down

1 comment on commit e61eb26

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 76.1% 4306/5658
🟡 Branches 65.79% 2240/3405
🟡 Functions 68.74% 695/1011
🟡 Lines 76.31% 4049/5306

Test suite run success

699 tests passing in 100 suites.

Report generated by 🧪jest coverage report action from e61eb26

Please sign in to comment.