Skip to content

Commit 1b8ee3b

Browse files
authored
fix: add missing import and update tests for branch template feature (#799)
* fix: add missing import and update tests for branch template feature - Add missing `import { $ } from 'bun'` in branch.ts - Add missing `labels` property to pull-request-target.test.ts fixture - Update branch-template tests to expect 5-word descriptions * address review feedback: update comment and add truncation test
1 parent c247cb1 commit 1b8ee3b

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/github/operations/branch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* - For Issues: Create a new branch
77
*/
88

9+
import { $ } from "bun";
910
import { execFileSync } from "child_process";
1011
import * as core from "@actions/core";
1112
import type { ParsedGitHubContext } from "../context";

src/utils/branch-template.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
const NUM_DESCRIPTION_WORDS = 5;
88

99
/**
10-
* Extracts the first `numWords` words from a title and converts them to kebab-case
10+
* Extracts the first 5 words from a title and converts them to kebab-case
1111
*/
12-
function extractDescription(title: string, numWords: number = NUM_DESCRIPTION_WORDS): string {
12+
function extractDescription(
13+
title: string,
14+
numWords: number = NUM_DESCRIPTION_WORDS,
15+
): string {
1316
if (!title || title.trim() === "") {
1417
return "";
1518
}

test/branch-template.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe("branch template utilities", () => {
156156
"Fix login bug with OAuth",
157157
);
158158

159-
expect(result).toBe("feature/fix-login-bug/123");
159+
expect(result).toBe("feature/fix-login-bug-with-oauth/123");
160160
});
161161

162162
it("should handle template with multiple variables including description", () => {
@@ -172,7 +172,9 @@ describe("branch template utilities", () => {
172172
"User authentication fails completely",
173173
);
174174

175-
expect(result).toBe("dev/bug/user-authentication-fails-issue_456");
175+
expect(result).toBe(
176+
"dev/bug/user-authentication-fails-completely-issue_456",
177+
);
176178
});
177179

178180
it("should handle description with special characters in template", () => {
@@ -187,7 +189,20 @@ describe("branch template utilities", () => {
187189
"Add: User Registration & Email Validation",
188190
);
189191

190-
expect(result).toBe("fix/add-user-registration-789");
192+
expect(result).toBe("fix/add-user-registration-email-789");
193+
});
194+
195+
it("should truncate descriptions to exactly 5 words", () => {
196+
const result = generateBranchName(
197+
"{{prefix}}{{description}}/{{entityNumber}}",
198+
"feature/",
199+
"issue",
200+
999,
201+
undefined,
202+
undefined,
203+
"This is a very long title with many more than five words in it",
204+
);
205+
expect(result).toBe("feature/this-is-a-very-long/999");
191206
});
192207

193208
it("should handle empty description in template", () => {

test/pull-request-target.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe("pull_request_target event support", () => {
8787
},
8888
comments: { nodes: [] },
8989
reviews: { nodes: [] },
90+
labels: { nodes: [] },
9091
},
9192
comments: [],
9293
changedFiles: [],

0 commit comments

Comments
 (0)