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
1 change: 1 addition & 0 deletions src/github/operations/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 5 additions & 2 deletions src/utils/branch-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand Down
21 changes: 18 additions & 3 deletions test/branch-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe("branch template utilities", () => {
"Fix login bug with OAuth",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test with a title containing more than 5 words to explicitly verify truncation behavior:

it("should truncate descriptions to exactly 5 words from longer titles", () => {
  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");
});

This would definitively verify the NUM_DESCRIPTION_WORDS=5 change is working correctly.

);

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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand Down
1 change: 1 addition & 0 deletions test/pull-request-target.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe("pull_request_target event support", () => {
},
comments: { nodes: [] },
reviews: { nodes: [] },
labels: { nodes: [] },
},
comments: [],
changedFiles: [],
Expand Down
Loading