mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
Add label to template variables
This commit is contained in:
@@ -81,6 +81,7 @@ describe("branch template utilities", () => {
|
||||
expect(result.entityType).toBe("issue");
|
||||
expect(result.entityNumber).toBe(123);
|
||||
expect(result.sha).toBe("abcdef12");
|
||||
expect(result.label).toBe("issue"); // fallback to entityType
|
||||
expect(result.timestamp).toMatch(/^\d{8}-\d{4}$/);
|
||||
expect(result.year).toMatch(/^\d{4}$/);
|
||||
expect(result.month).toMatch(/^\d{2}$/);
|
||||
@@ -103,6 +104,33 @@ describe("branch template utilities", () => {
|
||||
const result = createBranchTemplateVariables("test/", "pr", 456);
|
||||
expect(result.sha).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should use provided label when available", () => {
|
||||
const result = createBranchTemplateVariables(
|
||||
"test/",
|
||||
"issue",
|
||||
123,
|
||||
undefined,
|
||||
"bug",
|
||||
);
|
||||
expect(result.label).toBe("bug");
|
||||
});
|
||||
|
||||
it("should fallback to entityType when label is not provided", () => {
|
||||
const result = createBranchTemplateVariables("test/", "pr", 456);
|
||||
expect(result.label).toBe("pr");
|
||||
});
|
||||
|
||||
it("should fallback to entityType when label is empty string", () => {
|
||||
const result = createBranchTemplateVariables(
|
||||
"test/",
|
||||
"issue",
|
||||
789,
|
||||
undefined,
|
||||
"",
|
||||
);
|
||||
expect(result.label).toBe("issue");
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateBranchName", () => {
|
||||
@@ -153,5 +181,40 @@ describe("branch template utilities", () => {
|
||||
|
||||
expect(result).toBe("fix/pr-789-abcdef12");
|
||||
});
|
||||
|
||||
it("should use label in template when provided", () => {
|
||||
const template = "{{prefix}}{{label}}/{{entityNumber}}";
|
||||
const result = generateBranchName(
|
||||
template,
|
||||
"feature/",
|
||||
"issue",
|
||||
123,
|
||||
undefined,
|
||||
"bug",
|
||||
);
|
||||
|
||||
expect(result).toBe("feature/bug/123");
|
||||
});
|
||||
|
||||
it("should fallback to entityType when label template is used but no label provided", () => {
|
||||
const template = "{{prefix}}{{label}}-{{entityNumber}}";
|
||||
const result = generateBranchName(template, "fix/", "pr", 456);
|
||||
|
||||
expect(result).toBe("fix/pr-456");
|
||||
});
|
||||
|
||||
it("should handle template with both label and entityType", () => {
|
||||
const template = "{{prefix}}{{label}}-{{entityType}}_{{entityNumber}}";
|
||||
const result = generateBranchName(
|
||||
template,
|
||||
"dev/",
|
||||
"issue",
|
||||
789,
|
||||
undefined,
|
||||
"enhancement",
|
||||
);
|
||||
|
||||
expect(result).toBe("dev/enhancement-issue_789");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -61,6 +61,7 @@ describe("generatePrompt", () => {
|
||||
body: "This is a test PR",
|
||||
author: { login: "testuser" },
|
||||
state: "OPEN",
|
||||
labels: { nodes: [] },
|
||||
createdAt: "2023-01-01T00:00:00Z",
|
||||
additions: 15,
|
||||
deletions: 5,
|
||||
@@ -475,6 +476,7 @@ describe("generatePrompt", () => {
|
||||
body: "The login form is not working",
|
||||
author: { login: "testuser" },
|
||||
state: "OPEN",
|
||||
labels: { nodes: [] },
|
||||
createdAt: "2023-01-01T00:00:00Z",
|
||||
comments: {
|
||||
nodes: [],
|
||||
|
||||
@@ -28,6 +28,9 @@ describe("formatContext", () => {
|
||||
additions: 50,
|
||||
deletions: 30,
|
||||
state: "OPEN",
|
||||
labels: {
|
||||
nodes: [],
|
||||
},
|
||||
commits: {
|
||||
totalCount: 3,
|
||||
nodes: [],
|
||||
@@ -63,6 +66,9 @@ Changed Files: 2 files`,
|
||||
author: { login: "test-user" },
|
||||
createdAt: "2023-01-01T00:00:00Z",
|
||||
state: "OPEN",
|
||||
labels: {
|
||||
nodes: [],
|
||||
},
|
||||
comments: {
|
||||
nodes: [],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user