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

[CLI-FEATURE] add registries options for oc publish #1277

Merged
merged 5 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
5 changes: 5 additions & 0 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export default {
boolean: true,
description: 'Skip packaging step',
default: false
},
registries: {
array: true,
description:
'List of registries to publish to. This setting will take precedence over oc.json file'
}
},
description: 'Publish a component',
Expand Down
11 changes: 10 additions & 1 deletion src/cli/facade/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const publish =
skipPackage?: boolean;
username?: string;
password?: string;
registries?: string[];
},
callback: (err?: Error | string) => void
): void => {
Expand Down Expand Up @@ -91,6 +92,14 @@ const publish =
});
};

const getRegistries = (
cb: (err: string | null, registryLocations: string[]) => void
): void => {
if (opts.registries) return cb(null, opts.registries);

registry.get(cb);
};

const putComponentToRegistry = (
options: {
route: string;
Expand Down Expand Up @@ -181,7 +190,7 @@ const publish =
);
};

registry.get((err: string | null, registryLocations: string[]) => {
getRegistries((err: string | null, registryLocations: string[]) => {
if (err) {
logger.err(err);
return callback(err);
Expand Down
19 changes: 17 additions & 2 deletions test/unit/cli-facade-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('cli : facade : publish', () => {

const execute = function (
cb,
{ creds = {}, skipPackage = false, fs = {} } = {}
{ creds = {}, skipPackage = false, fs = {}, registries } = {}
) {
logSpy.err = sinon.stub();
logSpy.log = sinon.stub();
Expand All @@ -47,7 +47,8 @@ describe('cli : facade : publish', () => {
componentPath: 'test/fixtures/components/hello-world/',
username: creds.username,
password: creds.password,
skipPackage
skipPackage,
registries
},
() => {
cb();
Expand Down Expand Up @@ -101,6 +102,20 @@ describe('cli : facade : publish', () => {
});
});

it('should take precedence over the registries set through oc.json', done => {
sinon.stub(registry, 'putComponent').yields(null, 'ok');
execute(
() => {
registry.putComponent.restore();

expect(logSpy.ok.args[0][0]).to.include('http://www.newapi.com');
expect(logSpy.ok.args[1][0]).to.include('http://www.newapi2.com');
done();
},
{ registries: ['http://www.newapi.com', 'http://www.newapi2.com'] }
);
});

describe('when packaging', () => {
describe('when a component is not valid', () => {
beforeEach(done => {
Expand Down