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
3 changes: 2 additions & 1 deletion src/commands/configuration-management/studio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/core/utils/branches.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
25 changes: 25 additions & 0 deletions tests/core/utils/branches.spec.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
});
Loading