From 45ee2dca55c6082b67de2b5ab5a1e78fcc409eae Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Sat, 31 May 2025 01:10:59 +0100 Subject: [PATCH] Attempt to make this work --- README.md | 6 +++--- src/create-prompt/index.ts | 11 +---------- src/github/operations/branch-cleanup.ts | 10 +++++----- src/github/operations/comment-logic.ts | 2 +- src/github/operations/comments/common.ts | 11 +---------- test/branch-cleanup.test.ts | 4 ++-- test/comment-logic.test.ts | 16 ++++++++-------- 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 72b8e51..a3692e3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -![Claude Code Action responding to a comment](https://github.com/user-attachments/assets/1d60c2e9-82ed-4ee5-b749-f9e021c85f4d) +# Claude Code Action (Gitea Fork) -# Claude Code Action +A fork of the [Claude Code Action](https://github.com/anthropics/claude-code-action) that adds support for Gitea alongside GitHub. This action provides a general-purpose [Claude Code](https://claude.ai/code) assistant for PRs and issues that can answer questions and implement code changes. It listens for a trigger phrase in comments and activates Claude to act on the request. Supports multiple authentication methods including Anthropic direct API, Amazon Bedrock, and Google Vertex AI. -A general-purpose [Claude Code](https://claude.ai/code) action for GitHub PRs and issues that can answer questions and implement code changes. This action listens for a trigger phrase in comments and activates Claude act on the request. It supports multiple authentication methods including Anthropic direct API, Amazon Bedrock, and Google Vertex AI. +> **Note**: This is an unofficial fork that extends the original action to work with Gitea installations. The core functionality remains the same, with additional support for Gitea APIs and local git operations. ## Features diff --git a/src/create-prompt/index.ts b/src/create-prompt/index.ts index b5de87a..30d742e 100644 --- a/src/create-prompt/index.ts +++ b/src/create-prompt/index.ts @@ -584,16 +584,7 @@ Important Notes: - Never create new comments. Only update the existing comment using ${eventData.eventName === "pull_request_review_comment" ? "mcp__github__update_pull_request_comment" : "mcp__github__update_issue_comment"} with comment_id: ${context.claudeCommentId}. - This includes ALL responses: code reviews, answers to questions, progress updates, and final results.${eventData.isPR ? "\n- PR CRITICAL: After reading files and forming your response, you MUST post it by calling mcp__github__update_issue_comment. Do NOT just respond with a normal response, the user will not see it." : ""} - You communicate exclusively by editing your single comment - not through any other means. -- Use this spinner HTML when work is in progress: ${(() => { - try { - const spinnerPath = require("path").join(__dirname, "../assets/spinner.gif"); - const spinnerBuffer = require("fs").readFileSync(spinnerPath); - const base64Data = spinnerBuffer.toString("base64"); - return ``; - } catch (error) { - return ''; - } -})()} +- Use this spinner HTML when work is in progress: ${eventData.isPR && !eventData.claudeBranch ? `- Always push to the existing branch when triggered on a PR.` : `- IMPORTANT: You are already on the correct branch (${eventData.claudeBranch || "the created branch"}). Never create new branches when triggered on issues or closed/merged PRs.`} - Use mcp__local_git_ops__commit_files for making commits (works for both new and existing files, single or multiple). Use mcp__local_git_ops__delete_files for deleting files (supports deleting single or multiple files atomically), or mcp__github__delete_file for deleting a single file. Edit files locally, and the tool will read the content from the same path on disk. Tool usage examples: diff --git a/src/github/operations/branch-cleanup.ts b/src/github/operations/branch-cleanup.ts index e8ab547..ab64d38 100644 --- a/src/github/operations/branch-cleanup.ts +++ b/src/github/operations/branch-cleanup.ts @@ -46,7 +46,7 @@ export async function checkAndDeleteEmptyBranch( console.log( `Branch ${claudeBranch} appears to have commits (different SHA from base)`, ); - const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/src/branch/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } else { console.log( @@ -63,7 +63,7 @@ export async function checkAndDeleteEmptyBranch( console.log( `Branch ${claudeBranch} exists but SHA comparison failed, assuming it has commits`, ); - const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/src/branch/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } else { console.log( @@ -76,7 +76,7 @@ export async function checkAndDeleteEmptyBranch( console.error("Error checking branch with git commands:", error); // For errors, assume the branch has commits to be safe console.log("Assuming branch exists due to git command error"); - const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/src/branch/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } } else { @@ -106,7 +106,7 @@ export async function checkAndDeleteEmptyBranch( console.log( `Branch ${claudeBranch} appears to have commits (different SHA from base)`, ); - const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/src/branch/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } else { console.log( @@ -127,7 +127,7 @@ export async function checkAndDeleteEmptyBranch( } else { // For other errors, assume the branch has commits to be safe console.log("Assuming branch exists due to non-404 error"); - const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/src/branch/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } } diff --git a/src/github/operations/comment-logic.ts b/src/github/operations/comment-logic.ts index e0561d0..440d5a5 100644 --- a/src/github/operations/comment-logic.ts +++ b/src/github/operations/comment-logic.ts @@ -160,7 +160,7 @@ export function updateCommentBody(input: CommentUpdateInput): string { // Extract owner/repo from jobUrl const repoMatch = jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//); if (repoMatch) { - branchUrl = `${GITEA_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`; + branchUrl = `${GITEA_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/src/branch/${finalBranchName}`; } } diff --git a/src/github/operations/comments/common.ts b/src/github/operations/comments/common.ts index e1828e4..7c3793f 100644 --- a/src/github/operations/comments/common.ts +++ b/src/github/operations/comments/common.ts @@ -3,16 +3,7 @@ import { readFileSync } from "fs"; import { join } from "path"; function getSpinnerHtml(): string { - try { - const spinnerPath = join(__dirname, "../../../assets/spinner.gif"); - const spinnerBuffer = readFileSync(spinnerPath); - const base64Data = spinnerBuffer.toString("base64"); - return ``; - } catch (error) { - console.warn("Could not load spinner image, using fallback"); - // Fallback to a simple text spinner - return ''; - } + return ``; } export const SPINNER_HTML = getSpinnerHtml(); diff --git a/test/branch-cleanup.test.ts b/test/branch-cleanup.test.ts index 5ddf241..eef7fad 100644 --- a/test/branch-cleanup.test.ts +++ b/test/branch-cleanup.test.ts @@ -88,7 +88,7 @@ describe("checkAndDeleteEmptyBranch", () => { expect(result.shouldDeleteBranch).toBe(false); expect(result.branchLink).toBe( - `\n[View branch](${GITEA_SERVER_URL}/owner/repo/tree/claude/issue-123-20240101_123456)`, + `\n[View branch](${GITEA_SERVER_URL}/owner/repo/src/branch/claude/issue-123-20240101_123456)`, ); expect(consoleLogSpy).not.toHaveBeenCalledWith( expect.stringContaining("has no commits"), @@ -119,7 +119,7 @@ describe("checkAndDeleteEmptyBranch", () => { expect(result.shouldDeleteBranch).toBe(false); expect(result.branchLink).toBe( - `\n[View branch](${GITEA_SERVER_URL}/owner/repo/tree/claude/issue-123-20240101_123456)`, + `\n[View branch](${GITEA_SERVER_URL}/owner/repo/src/branch/claude/issue-123-20240101_123456)`, ); expect(consoleErrorSpy).toHaveBeenCalledWith( "Error checking for commits on Claude branch:", diff --git a/test/comment-logic.test.ts b/test/comment-logic.test.ts index 82fec08..ed2afa2 100644 --- a/test/comment-logic.test.ts +++ b/test/comment-logic.test.ts @@ -105,7 +105,7 @@ describe("updateCommentBody", () => { const result = updateCommentBody(input); expect(result).toContain( - "• [`claude/issue-123-20240101_120000`](https://github.com/owner/repo/tree/claude/issue-123-20240101_120000)", + "• [`claude/issue-123-20240101_120000`](https://github.com/owner/repo/src/branch/claude/issue-123-20240101_120000)", ); }); @@ -113,12 +113,12 @@ describe("updateCommentBody", () => { const input = { ...baseInput, branchLink: - "\n[View branch](https://github.com/owner/repo/tree/branch-name)", + "\n[View branch](https://github.com/owner/repo/src/branch/branch-name)", }; const result = updateCommentBody(input); expect(result).toContain( - "• [`branch-name`](https://github.com/owner/repo/tree/branch-name)", + "• [`branch-name`](https://github.com/owner/repo/src/branch/branch-name)", ); }); @@ -126,13 +126,13 @@ describe("updateCommentBody", () => { const input = { ...baseInput, currentBody: - "Some comment with [View branch](https://github.com/owner/repo/tree/branch-name)", + "Some comment with [View branch](https://github.com/owner/repo/src/branch/branch-name)", branchName: "new-branch-name", }; const result = updateCommentBody(input); expect(result).toContain( - "• [`new-branch-name`](https://github.com/owner/repo/tree/new-branch-name)", + "• [`new-branch-name`](https://github.com/owner/repo/src/branch/new-branch-name)", ); expect(result).not.toContain("View branch"); }); @@ -333,7 +333,7 @@ describe("updateCommentBody", () => { ); expect(result).toContain("—— [View job]"); expect(result).toContain( - "• [`claude-branch-123`](https://github.com/owner/repo/tree/claude-branch-123)", + "• [`claude-branch-123`](https://github.com/owner/repo/src/branch/claude-branch-123)", ); expect(result).toContain("• [Create PR ➔]"); @@ -402,7 +402,7 @@ describe("updateCommentBody", () => { currentBody: "Claude Code is working…", branchName: "claude/issue-123-20240101_120000", branchLink: - "\n[View branch](https://github.com/owner/repo/tree/claude/issue-123-20240101_120000)", + "\n[View branch](https://github.com/owner/repo/src/branch/claude/issue-123-20240101_120000)", prLink: "\n[Create a PR](https://github.com/owner/repo/compare/main...claude/issue-123-20240101_120000)", }; @@ -411,7 +411,7 @@ describe("updateCommentBody", () => { // Should include both links in formatted style expect(result).toContain( - "• [`claude/issue-123-20240101_120000`](https://github.com/owner/repo/tree/claude/issue-123-20240101_120000)", + "• [`claude/issue-123-20240101_120000`](https://github.com/owner/repo/src/branch/claude/issue-123-20240101_120000)", ); expect(result).toContain( "• [Create PR ➔](https://github.com/owner/repo/compare/main...claude/issue-123-20240101_120000)",