Merge branch 'feat/give-claude-access-to-switch-branch' of github.com:markwylde/claude-code-gitea-action into gitea

This commit is contained in:
Mark Wylde
2025-05-31 09:48:49 +01:00
3 changed files with 16 additions and 27 deletions

View File

@@ -219,8 +219,6 @@ export function prepareContext(
...(baseBranch && { baseBranch }), ...(baseBranch && { baseBranch }),
}; };
break; break;
} else if (!claudeBranch) {
throw new Error("CLAUDE_BRANCH is required for issue_comment event");
} else if (!baseBranch) { } else if (!baseBranch) {
throw new Error("BASE_BRANCH is required for issue_comment event"); throw new Error("BASE_BRANCH is required for issue_comment event");
} else if (!issueNumber) { } else if (!issueNumber) {
@@ -233,10 +231,10 @@ export function prepareContext(
eventName: "issue_comment", eventName: "issue_comment",
commentId, commentId,
isPR: false, isPR: false,
claudeBranch: claudeBranch,
baseBranch, baseBranch,
issueNumber, issueNumber,
commentBody, commentBody,
...(claudeBranch && { claudeBranch }),
}; };
break; break;
@@ -253,9 +251,6 @@ export function prepareContext(
if (!baseBranch) { if (!baseBranch) {
throw new Error("BASE_BRANCH is required for issues event"); throw new Error("BASE_BRANCH is required for issues event");
} }
if (!claudeBranch) {
throw new Error("CLAUDE_BRANCH is required for issues event");
}
if (eventAction === "assigned") { if (eventAction === "assigned") {
if (!assigneeTrigger) { if (!assigneeTrigger) {
@@ -269,8 +264,8 @@ export function prepareContext(
isPR: false, isPR: false,
issueNumber, issueNumber,
baseBranch, baseBranch,
claudeBranch,
assigneeTrigger, assigneeTrigger,
...(claudeBranch && { claudeBranch }),
}; };
} else if (eventAction === "opened") { } else if (eventAction === "opened") {
eventData = { eventData = {
@@ -279,7 +274,7 @@ export function prepareContext(
isPR: false, isPR: false,
issueNumber, issueNumber,
baseBranch, baseBranch,
claudeBranch, ...(claudeBranch && { claudeBranch }),
}; };
} else { } else {
throw new Error(`Unsupported issue action: ${eventAction}`); throw new Error(`Unsupported issue action: ${eventAction}`);

View File

@@ -34,7 +34,7 @@ type IssueCommentEvent = {
issueNumber: string; issueNumber: string;
isPR: false; isPR: false;
baseBranch: string; baseBranch: string;
claudeBranch: string; claudeBranch?: string;
commentBody: string; commentBody: string;
}; };
@@ -55,7 +55,7 @@ type IssueOpenedEvent = {
isPR: false; isPR: false;
issueNumber: string; issueNumber: string;
baseBranch: string; baseBranch: string;
claudeBranch: string; claudeBranch?: string;
}; };
type IssueAssignedEvent = { type IssueAssignedEvent = {
@@ -64,7 +64,7 @@ type IssueAssignedEvent = {
isPR: false; isPR: false;
issueNumber: string; issueNumber: string;
baseBranch: string; baseBranch: string;
claudeBranch: string; claudeBranch?: string;
assigneeTrigger: string; assigneeTrigger: string;
}; };

View File

@@ -317,7 +317,7 @@ describe("generatePrompt", () => {
expect(prompt).toContain("<trigger_username>johndoe</trigger_username>"); expect(prompt).toContain("<trigger_username>johndoe</trigger_username>");
expect(prompt).toContain( expect(prompt).toContain(
"Co-authored-by: johndoe <johndoe@users.noreply.github.com>", "Co-authored-by: johndoe <johndoe@users.noreply.local>",
); );
}); });
@@ -338,7 +338,7 @@ describe("generatePrompt", () => {
// Should contain PR-specific instructions // Should contain PR-specific instructions
expect(prompt).toContain( expect(prompt).toContain(
"Push directly using mcp__github_file_ops__commit_files to the existing branch", "Commit changes using mcp__local_git_ops__commit_files to the existing branch",
); );
expect(prompt).toContain( expect(prompt).toContain(
"Always push to the existing branch when triggered on a PR", "Always push to the existing branch when triggered on a PR",
@@ -378,12 +378,12 @@ describe("generatePrompt", () => {
); );
expect(prompt).toContain("Create a PR](https://github.com/"); expect(prompt).toContain("Create a PR](https://github.com/");
expect(prompt).toContain( expect(prompt).toContain(
"If you created anything in your branch, your comment must include the PR URL", "If you created a branch and made changes, your comment must include the PR URL",
); );
// Should NOT contain PR-specific instructions // Should NOT contain PR-specific instructions
expect(prompt).not.toContain( expect(prompt).not.toContain(
"Push directly using mcp__github_file_ops__commit_files to the existing branch", "Commit changes using mcp__local_git_ops__commit_files to the existing branch",
); );
expect(prompt).not.toContain( expect(prompt).not.toContain(
"Always push to the existing branch when triggered on a PR", "Always push to the existing branch when triggered on a PR",
@@ -449,13 +449,10 @@ describe("generatePrompt", () => {
"The branch-name is the current branch: claude/pr-456-20240101_120000", "The branch-name is the current branch: claude/pr-456-20240101_120000",
); );
expect(prompt).toContain("Reference to the original PR"); expect(prompt).toContain("Reference to the original PR");
expect(prompt).toContain(
"If you created anything in your branch, your comment must include the PR URL",
);
// Should NOT contain open PR instructions // Should NOT contain open PR instructions
expect(prompt).not.toContain( expect(prompt).not.toContain(
"Push directly using mcp__github_file_ops__commit_files to the existing branch", "Commit changes using mcp__local_git_ops__commit_files to the existing branch",
); );
}); });
@@ -478,7 +475,7 @@ describe("generatePrompt", () => {
// Should contain open PR instructions // Should contain open PR instructions
expect(prompt).toContain( expect(prompt).toContain(
"Push directly using mcp__github_file_ops__commit_files to the existing branch", "Commit changes using mcp__local_git_ops__commit_files to the existing branch",
); );
expect(prompt).toContain( expect(prompt).toContain(
"Always push to the existing branch when triggered on a PR", "Always push to the existing branch when triggered on a PR",
@@ -543,9 +540,6 @@ describe("generatePrompt", () => {
); );
expect(prompt).toContain("Create a PR](https://github.com/"); expect(prompt).toContain("Create a PR](https://github.com/");
expect(prompt).toContain("Reference to the original PR"); expect(prompt).toContain("Reference to the original PR");
expect(prompt).toContain(
"If you created anything in your branch, your comment must include the PR URL",
);
}); });
test("should handle pull_request event on closed PR with new branch", () => { test("should handle pull_request event on closed PR with new branch", () => {
@@ -638,8 +632,8 @@ describe("buildAllowedToolsString", () => {
expect(result).toContain("Write"); expect(result).toContain("Write");
expect(result).toContain("mcp__github__update_issue_comment"); expect(result).toContain("mcp__github__update_issue_comment");
expect(result).not.toContain("mcp__github__update_pull_request_comment"); expect(result).not.toContain("mcp__github__update_pull_request_comment");
expect(result).toContain("mcp__github_file_ops__commit_files"); expect(result).toContain("mcp__local_git_ops__commit_files");
expect(result).toContain("mcp__github_file_ops__delete_files"); expect(result).toContain("mcp__local_git_ops__delete_files");
}); });
test("should return PR comment tool for inline review comments", () => { test("should return PR comment tool for inline review comments", () => {
@@ -662,8 +656,8 @@ describe("buildAllowedToolsString", () => {
expect(result).toContain("Write"); expect(result).toContain("Write");
expect(result).not.toContain("mcp__github__update_issue_comment"); expect(result).not.toContain("mcp__github__update_issue_comment");
expect(result).toContain("mcp__github__update_pull_request_comment"); expect(result).toContain("mcp__github__update_pull_request_comment");
expect(result).toContain("mcp__github_file_ops__commit_files"); expect(result).toContain("mcp__local_git_ops__commit_files");
expect(result).toContain("mcp__github_file_ops__delete_files"); expect(result).toContain("mcp__local_git_ops__delete_files");
}); });
test("should append custom tools when provided", () => { test("should append custom tools when provided", () => {