diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index b36e9d8..aea1b9c 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -6,6 +6,7 @@ * - For Issues: Create a new branch */ +import { $ } from "bun"; import { execFileSync } from "child_process"; import * as core from "@actions/core"; import type { ParsedGitHubContext } from "../context"; diff --git a/src/utils/branch-template.ts b/src/utils/branch-template.ts index cc15d9d..0056dd6 100644 --- a/src/utils/branch-template.ts +++ b/src/utils/branch-template.ts @@ -7,9 +7,12 @@ const NUM_DESCRIPTION_WORDS = 5; /** - * Extracts the first `numWords` words from a title and converts them to kebab-case + * Extracts the first 5 words from a title and converts them to kebab-case */ -function extractDescription(title: string, numWords: number = NUM_DESCRIPTION_WORDS): string { +function extractDescription( + title: string, + numWords: number = NUM_DESCRIPTION_WORDS, +): string { if (!title || title.trim() === "") { return ""; } diff --git a/test/branch-template.test.ts b/test/branch-template.test.ts index 4ad2b6e..62ab6c1 100644 --- a/test/branch-template.test.ts +++ b/test/branch-template.test.ts @@ -156,7 +156,7 @@ describe("branch template utilities", () => { "Fix login bug with OAuth", ); - expect(result).toBe("feature/fix-login-bug/123"); + expect(result).toBe("feature/fix-login-bug-with-oauth/123"); }); it("should handle template with multiple variables including description", () => { @@ -172,7 +172,9 @@ describe("branch template utilities", () => { "User authentication fails completely", ); - expect(result).toBe("dev/bug/user-authentication-fails-issue_456"); + expect(result).toBe( + "dev/bug/user-authentication-fails-completely-issue_456", + ); }); it("should handle description with special characters in template", () => { @@ -187,7 +189,20 @@ describe("branch template utilities", () => { "Add: User Registration & Email Validation", ); - expect(result).toBe("fix/add-user-registration-789"); + expect(result).toBe("fix/add-user-registration-email-789"); + }); + + it("should truncate descriptions to exactly 5 words", () => { + const result = generateBranchName( + "{{prefix}}{{description}}/{{entityNumber}}", + "feature/", + "issue", + 999, + undefined, + undefined, + "This is a very long title with many more than five words in it", + ); + expect(result).toBe("feature/this-is-a-very-long/999"); }); it("should handle empty description in template", () => { diff --git a/test/pull-request-target.test.ts b/test/pull-request-target.test.ts index de0fe62..48bfd19 100644 --- a/test/pull-request-target.test.ts +++ b/test/pull-request-target.test.ts @@ -87,6 +87,7 @@ describe("pull_request_target event support", () => { }, comments: { nodes: [] }, reviews: { nodes: [] }, + labels: { nodes: [] }, }, comments: [], changedFiles: [],