diff --git a/actions/cursor-deploy/dist/main/index.js b/actions/cursor-deploy/dist/main/index.js index ec1cdb11..1a5ada6c 100644 --- a/actions/cursor-deploy/dist/main/index.js +++ b/actions/cursor-deploy/dist/main/index.js @@ -9737,8 +9737,8 @@ async function getDeploymentHash(deployMode, rollbackCommitHash) { return treeHash; } function branchNameToHostnameLabel(ref) { - var _a; - const hostnameLabel = (_a = ref == null ? void 0 : ref.split("refs/heads/").pop()) == null ? void 0 : _a.replace(/[^\w]/gi, "-").replace(/-{2,}/gi, "-").toLowerCase().slice(0, 60).trim(); + var _a, _b; + const hostnameLabel = (_b = (_a = ref == null ? void 0 : ref.split("refs/heads/").pop()) == null ? void 0 : _a.replace(/[^\w]/gi, "-").replace(/-{2,}/gi, "-").toLowerCase().slice(0, 60)) == null ? void 0 : _b.replace(/(-|_)$/gi, "").trim(); if (!hostnameLabel) { throw new Error("Could not get a valid hostname label from branch name"); } diff --git a/actions/cursor-deploy/index.test.ts b/actions/cursor-deploy/index.test.ts index fb3bd530..eb2f0a57 100644 --- a/actions/cursor-deploy/index.test.ts +++ b/actions/cursor-deploy/index.test.ts @@ -338,6 +338,33 @@ describe('Branch Sanitize - branchNameToHostnameLabel', () => { ) expect(output).toBe('hello-my-very-weird_branch-100-original-whoooohoooooo-lets-d') }) + + it(`trims trailing hyphens when the branch name exceeds the max allowed length`, async () => { + const output = branchNameToHostnameLabel( + 'refs/heads/feature-hello-0000-the-quick-brown-fox-jumped-over-the-lazy-dog' // the 60th character here (minus 'refs/heads/') is a hyphen + ) + expect(output).toBe('feature-hello-0000-the-quick-brown-fox-jumped-over-the-lazy') + }) + + it(`trims trailing hyphens when the branch name does not exceed the max allowed length`, async () => { + const output = branchNameToHostnameLabel('refs/heads/feature-hello-0000-') + expect(output).toBe('feature-hello-0000') + }) + + it(`trims multiple hyphens`, async () => { + const output = branchNameToHostnameLabel('refs/heads/feature-hello-0000--') + expect(output).toBe('feature-hello-0000') + }) + + it(`trims trailing underscores`, async () => { + const output = branchNameToHostnameLabel('refs/heads/feature_hello_0000_') + expect(output).toBe('feature_hello_0000') + }) + + it(`trims whitespace`, async () => { + const output = branchNameToHostnameLabel(' refs/heads/feature-hello-0000 ') + expect(output).toBe('feature-hello-0000') + }) }) //#region Custom Assertions diff --git a/actions/cursor-deploy/index.ts b/actions/cursor-deploy/index.ts index eeef06d9..f3991e75 100644 --- a/actions/cursor-deploy/index.ts +++ b/actions/cursor-deploy/index.ts @@ -153,6 +153,7 @@ export function branchNameToHostnameLabel(ref: string) { .replace(/-{2,}/gi, '-') // get rid of multiple consecutive "-" .toLowerCase() .slice(0, 60) + ?.replace(/(-|_)$/gi, '') // get rid of trailing "-" and "_" .trim() if (!hostnameLabel) {