mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
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
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
* - For Issues: Create a new branch
|
* - For Issues: Create a new branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { $ } from "bun";
|
||||||
import { execFileSync } from "child_process";
|
import { execFileSync } from "child_process";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import type { ParsedGitHubContext } from "../context";
|
import type { ParsedGitHubContext } from "../context";
|
||||||
|
|||||||
@@ -7,9 +7,12 @@
|
|||||||
const NUM_DESCRIPTION_WORDS = 5;
|
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() === "") {
|
if (!title || title.trim() === "") {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ describe("branch template utilities", () => {
|
|||||||
"Fix login bug with OAuth",
|
"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", () => {
|
it("should handle template with multiple variables including description", () => {
|
||||||
@@ -172,7 +172,9 @@ describe("branch template utilities", () => {
|
|||||||
"User authentication fails completely",
|
"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", () => {
|
it("should handle description with special characters in template", () => {
|
||||||
@@ -187,7 +189,20 @@ describe("branch template utilities", () => {
|
|||||||
"Add: User Registration & Email Validation",
|
"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", () => {
|
it("should handle empty description in template", () => {
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ describe("pull_request_target event support", () => {
|
|||||||
},
|
},
|
||||||
comments: { nodes: [] },
|
comments: { nodes: [] },
|
||||||
reviews: { nodes: [] },
|
reviews: { nodes: [] },
|
||||||
|
labels: { nodes: [] },
|
||||||
},
|
},
|
||||||
comments: [],
|
comments: [],
|
||||||
changedFiles: [],
|
changedFiles: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user