Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ export class BatchImportExportApi {
this.httpClient = () => context.httpClient;
}

public async findAllActivePackages(flavors: string[], withDependencies: boolean = false): Promise<PackageExportTransport[]> {
public async findAllActivePackages(flavors: string[], withDependencies: boolean = false, includeBranches: boolean = false): Promise<PackageExportTransport[]> {
const queryParams = new URLSearchParams();

queryParams.set("withDependencies", withDependencies.toString());
queryParams.set("includeBranches", includeBranches.toString());
flavors.forEach(flavor => queryParams.append("flavors", flavor))

return this.httpClient().get(`/package-manager/api/core/packages/export/list?${queryParams.toString()}`).catch(e => {
throw new FatalError(`Problem getting active packages: ${e}`);
});
}

public async findActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string): Promise<PackageExportTransport[]> {
public async findActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string, includeBranches: boolean = false): Promise<PackageExportTransport[]> {
const queryParams = new URLSearchParams();

queryParams.set("variableValue", variableValue);
if (variableType) {
queryParams.set("variableType", variableType);
}
queryParams.set("includeBranches", includeBranches.toString());
flavors.forEach(flavor => queryParams.append("flavors", flavor))

return this.httpClient().get(`/package-manager/api/core/packages/export/list-by-variable-value?${queryParams.toString()}`).catch(e => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ export class BatchImportExportService {
this.gitService = new GitService(context);
}

public async listActivePackages(flavors: string[]): Promise<void> {
const activePackages = await this.batchImportExportApi.findAllActivePackages(flavors);
public async listActivePackages(flavors: string[], includeBranches: boolean): Promise<void> {
const activePackages = await this.batchImportExportApi.findAllActivePackages(flavors, false, includeBranches);
activePackages.forEach(pkg => {
logger.info(`${pkg.name} - Key: "${pkg.key}"`)
});
}

public async findAndExportListOfPackages(flavors: string[], packageKeys: string[], keysByVersion: string[], withDependencies: boolean): Promise<void> {
public async findAndExportListOfPackages(flavors: string[], packageKeys: string[], keysByVersion: string[], withDependencies: boolean, includeBranches: boolean): Promise<void> {
let packagesToExport: PackageExportTransport[];

if (keysByVersion.length) {
packagesToExport = await this.batchImportExportApi.findPackagesByKeysAndVersion(keysByVersion, withDependencies);
} else if (packageKeys.length) {
packagesToExport = await this.batchImportExportApi.findActivePackagesByKeys(packageKeys, withDependencies);
} else {
packagesToExport = await this.batchImportExportApi.findAllActivePackages(flavors, withDependencies);
packagesToExport = await this.batchImportExportApi.findAllActivePackages(flavors, withDependencies, includeBranches);
}

packagesToExport = await this.studioService.getExportPackagesWithStudioData(packagesToExport, withDependencies);
Expand Down Expand Up @@ -159,16 +159,16 @@ export class BatchImportExportService {
logger.info("Config import report file: " + reportFileName);
}

public async findAndExportListOfActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string): Promise<void> {
let packagesToExport = await this.batchImportExportApi.findActivePackagesByVariableValue(flavors, variableValue, variableType);
public async findAndExportListOfActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string, includeBranches: boolean): Promise<void> {
let packagesToExport = await this.batchImportExportApi.findActivePackagesByVariableValue(flavors, variableValue, variableType, includeBranches);

packagesToExport = await this.studioService.getExportPackagesWithStudioData(packagesToExport, false);

this.exportListOfPackages(packagesToExport);
}

public async listActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string) : Promise<void> {
const packagesByVariableValue = await this.batchImportExportApi.findActivePackagesByVariableValue(flavors, variableValue, variableType);
public async listActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string, includeBranches: boolean) : Promise<void> {
const packagesByVariableValue = await this.batchImportExportApi.findActivePackagesByVariableValue(flavors, variableValue, variableType, includeBranches);
packagesByVariableValue.forEach(pkg => {
logger.info(`${pkg.name} - Key: "${pkg.key}"`)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
this.diffService = new DiffService(context);
}

public async listPackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys: string[], keysByVersion: string[], variableValue: string, variableType: string): Promise<void> {
public async listPackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys: string[], keysByVersion: string[], variableValue: string, variableType: string, includeBranches: boolean): Promise<void> {

Check warning on line 19 in src/commands/configuration-management/config-command.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'listPackages' has too many parameters (8). Maximum allowed is 7.

See more on https://sonarcloud.io/project/issues?id=celonis_content-cli&issues=AZ4C9HtVAFLIIvXHrk7o&open=AZ4C9HtVAFLIIvXHrk7o&pullRequest=349
if (variableValue) {
await this.listPackagesByVariableValue(jsonResponse, flavors, variableValue, variableType);
await this.listPackagesByVariableValue(jsonResponse, flavors, variableValue, variableType, includeBranches);
return;
}

if (jsonResponse) {
await this.batchImportExportService.findAndExportListOfPackages(flavors ?? [], packageKeys ?? [], keysByVersion ?? [], withDependencies);
await this.batchImportExportService.findAndExportListOfPackages(flavors ?? [], packageKeys ?? [], keysByVersion ?? [], withDependencies, includeBranches);
} else if (keysByVersion) {
await this.batchImportExportService.listPackagesByKeysWithVersion(keysByVersion, withDependencies);
} else {
await this.batchImportExportService.listActivePackages(flavors ?? []);
await this.batchImportExportService.listActivePackages(flavors ?? [], includeBranches);
}
}

Expand Down Expand Up @@ -82,11 +82,11 @@
return this.diffService.diffPackages(file, hasChanges, jsonResponse);
}

private async listPackagesByVariableValue(jsonResponse: boolean, flavors: string[], variableValue: string, variableType: string): Promise<void> {
private async listPackagesByVariableValue(jsonResponse: boolean, flavors: string[], variableValue: string, variableType: string, includeBranches: boolean): Promise<void> {
if (jsonResponse) {
await this.batchImportExportService.findAndExportListOfActivePackagesByVariableValue(flavors ?? [], variableValue, variableType )
await this.batchImportExportService.findAndExportListOfActivePackagesByVariableValue(flavors ?? [], variableValue, variableType, includeBranches)
} else {
await this.batchImportExportService.listActivePackagesByVariableValue(flavors ?? [], variableValue, variableType);
await this.batchImportExportService.listActivePackagesByVariableValue(flavors ?? [], variableValue, variableType, includeBranches);
}
}
}
12 changes: 11 additions & 1 deletion src/commands/configuration-management/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Module extends IModule {
.option("--keysByVersion <keysByVersion...>", "Lists packages by given key and version [packageKey.version]")
.option("--variableValue <variableValue>", "Variable value for filtering packages by.")
.option("--variableType <variableType>", "Variable type for filtering packages by.")
.option("--branches", "Include branches", false)
.action(this.listPackages);

configCommand.command("export")
Expand Down Expand Up @@ -185,7 +186,16 @@ class Module extends IModule {
if (options.packageKeys && options.keysByVersion) {
throw new Error("Please provide either --packageKeys or --keysByVersion, but not both.");
}
await new ConfigCommandService(context).listPackages(options.json, options.flavors, options.withDependencies, options.packageKeys, options.keysByVersion, options.variableValue, options.variableType);

await new ConfigCommandService(context).listPackages(
options.json,
options.flavors,
options.withDependencies,
options.packageKeys,
options.keysByVersion,
options.variableValue,
options.variableType,
options.branches);
}

private async batchExportPackages(context: Context, command: Command, options: OptionValues): Promise<void> {
Expand Down
29 changes: 15 additions & 14 deletions tests/commands/configuration-management/config-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ describe("Config list", () => {

const urlParams = new URLSearchParams();
urlParams.set("withDependencies", "false");
urlParams.set("includeBranches", "false");
flavorsArray.forEach(flavor => urlParams.append("flavors", flavor));

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?" + urlParams.toString(), [firstPackage, secondPackage]);

await new ConfigCommandService(testContext).listPackages(false, flavorsArray, false, [], undefined, null, null);
await new ConfigCommandService(testContext).listPackages(false, flavorsArray, false, [], undefined, null, null, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
Expand All @@ -46,10 +47,10 @@ describe("Config list", () => {

const studioPackage: ContentNodeTransport = PacmanApiUtils.buildContentNodeTransport("key-1", "spaceId-1");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?withDependencies=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?withDependencies=false&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);

await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, null, null);
await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, null, null, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -69,7 +70,7 @@ describe("Config list", () => {
const firstPackage = PacmanApiUtils.buildPackageExportTransport("key-1", "name-1");
const secondPackage = PacmanApiUtils.buildPackageExportTransport("key-2", "name-2");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?withDependencies=true", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?withDependencies=true&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);

const dataModelVariableAssignmentResponse: PackageWithVariableAssignments = {
Expand All @@ -95,7 +96,7 @@ describe("Config list", () => {
};
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/compute-pools/data-models/details", [dataModelDetailResponse]);

await new ConfigCommandService(testContext).listPackages(true, [], true, [], undefined, null, null);
await new ConfigCommandService(testContext).listPackages(true, [], true, [], undefined, null, null, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -120,7 +121,7 @@ describe("Config list", () => {
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-keys?packageKeys=key-1&packageKeys=key-2&withDependencies=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);

await new ConfigCommandService(testContext).listPackages(true, [], false, [firstPackage.key, secondPackage.key], undefined, null, null);
await new ConfigCommandService(testContext).listPackages(true, [], false, [firstPackage.key, secondPackage.key], undefined, null, null, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand Down Expand Up @@ -166,7 +167,7 @@ describe("Config list", () => {
};
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/compute-pools/data-models/details", [dataModelDetailResponse]);

await new ConfigCommandService(testContext).listPackages(true, [], true, [firstPackage.key, secondPackage.key], undefined, null, null);
await new ConfigCommandService(testContext).listPackages(true, [], true, [firstPackage.key, secondPackage.key], undefined, null, null, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -187,10 +188,10 @@ describe("Config list", () => {
const secondPackage = PacmanApiUtils.buildPackageExportTransport("key-2", "name-2");


mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);

await new ConfigCommandService(testContext).listPackages(false, [], false, [], undefined, "1", null);
await new ConfigCommandService(testContext).listPackages(false, [], false, [], undefined, "1", null, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
Expand All @@ -201,10 +202,10 @@ describe("Config list", () => {
const firstPackage = PacmanApiUtils.buildPackageExportTransport("key-1", "name-1");
const secondPackage = PacmanApiUtils.buildPackageExportTransport("key-2", "name-2");

mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1&includeBranches=false", [{...firstPackage}, {...secondPackage}]);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);

await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, "1", null);
await new ConfigCommandService(testContext).listPackages(true, [], false, [], undefined, "1", null, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand All @@ -224,7 +225,7 @@ describe("Config list", () => {
[firstPackage, secondPackage]
);

await new ConfigCommandService(testContext).listPackages(false, [], false, undefined, keysByVersion, null, null);
await new ConfigCommandService(testContext).listPackages(false, [], false, undefined, keysByVersion, null, null, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
expect(loggingTestTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
Expand All @@ -241,7 +242,7 @@ describe("Config list", () => {
[firstPackage, secondPackage]
);

await new ConfigCommandService(testContext).listPackages(false, [], true, undefined, keysByVersion, null, null);
await new ConfigCommandService(testContext).listPackages(false, [], true, undefined, keysByVersion, null, null, false);

expect(loggingTestTransport.logMessages.length).toBe(2);
})
Expand All @@ -259,7 +260,7 @@ describe("Config list", () => {
);
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);

await new ConfigCommandService(testContext).listPackages(true, [], false, [], keysByVersion, null, null);
await new ConfigCommandService(testContext).listPackages(true, [], false, [], keysByVersion, null, null, false);

const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];

Expand Down
23 changes: 23 additions & 0 deletions tests/commands/configuration-management/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe("Configuration Management Module - Action Validations", () => {
["package1", "package2"],
undefined,
undefined,
undefined,
undefined
);
});
Expand All @@ -91,10 +92,32 @@ describe("Configuration Management Module - Action Validations", () => {
undefined,
["package3.1.0.0", "package4.1.0.0"],
undefined,
undefined,
undefined
);
});
});
describe("branches validation", () => {
it("should pass validation when branches is provided", async () => {
const options: OptionValues = {
branches: true,
json: true,
};

await (module as any).listPackages(testContext, mockCommand, options);

expect(mockConfigCommandService.listPackages).toHaveBeenCalledWith(
true,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
true
);
});
});
});

describe("batchExportPackages validation", () => {
Expand Down
Loading