diff --git a/src/commands/configuration-management/studio.service.ts b/src/commands/configuration-management/studio.service.ts index 0f63162..b729460 100644 --- a/src/commands/configuration-management/studio.service.ts +++ b/src/commands/configuration-management/studio.service.ts @@ -23,6 +23,7 @@ import { SpaceApi } from "../studio/api/space-api"; import { StudioVariablesApi } from "../studio/api/studio-variables-api"; import { SpaceService } from "../studio/service/space.service"; import { StudioVariableService } from "../studio/service/studio-variable.service"; +import { BranchUtils } from "../../core/utils/branches"; export class StudioService { @@ -103,7 +104,7 @@ export class StudioService { } for (const manifest of studioManifests) { const existingPackage = existingStudioPackages.find(existingPackage => existingPackage.key === manifest.packageKey); - if (existingPackage) { + if (existingPackage && !BranchUtils.isBranchPackageKey(existingPackage.key)) { await this.studioPackageApi.movePackageToSpace(existingPackage.id, manifest.space.id); } await this.assignRuntimeVariables(manifest); diff --git a/src/core/utils/branches.ts b/src/core/utils/branches.ts new file mode 100644 index 0000000..d205291 --- /dev/null +++ b/src/core/utils/branches.ts @@ -0,0 +1,11 @@ +export class BranchUtils { + private static readonly BRANCH_SEPARATOR = "@"; + + public static isBranchPackageKey(packageKey: string): boolean { + if (!packageKey || packageKey.trim().length === 0) { + throw new Error("Package key cannot be empty"); + } + + return packageKey.includes(BranchUtils.BRANCH_SEPARATOR); + } +} \ No newline at end of file diff --git a/tests/core/utils/branches.spec.ts b/tests/core/utils/branches.spec.ts new file mode 100644 index 0000000..bfff629 --- /dev/null +++ b/tests/core/utils/branches.spec.ts @@ -0,0 +1,25 @@ +import { BranchUtils } from "../../../src/core/utils/branches"; + +describe("BranchUtils", () => { + describe("isBranchPackageKey", () => { + it("should return true when package key contains branch separator", () => { + expect(BranchUtils.isBranchPackageKey("package@feature-branch")).toBe(true); + }); + + it("should return false when package key does not contain branch separator", () => { + expect(BranchUtils.isBranchPackageKey("package")).toBe(false); + }); + + it("should throw an error if the input is empty", () => { + expect(() => BranchUtils.isBranchPackageKey("")).toThrow("Package key cannot be empty"); + }); + + it("should throw an error if the input is only whitespace", () => { + expect(() => BranchUtils.isBranchPackageKey(" ")).toThrow("Package key cannot be empty"); + }); + + it("should throw an error if the input is null", () => { + expect(() => BranchUtils.isBranchPackageKey(null)).toThrow("Package key cannot be empty"); + }); + }); +});