diff --git a/src/create-prompt/index.ts b/src/create-prompt/index.ts index 93bca54..b866efb 100644 --- a/src/create-prompt/index.ts +++ b/src/create-prompt/index.ts @@ -19,7 +19,7 @@ import { } from "../github/context"; import type { ParsedGitHubContext } from "../github/context"; import type { CommonFields, PreparedContext, EventData } from "./types"; -import { GITHUB_SERVER_URL } from "../github/api/config"; +import { GITEA_SERVER_URL } from "../github/api/config"; export type { CommonFields, PreparedContext } from "./types"; const BASE_ALLOWED_TOOLS = [ @@ -541,10 +541,10 @@ ${context.directPrompt ? ` - DIRECT INSTRUCTION: A direct instruction was prov ${ eventData.claudeBranch ? `- Provide a URL to create a PR manually in this format: - [Create a PR](${GITHUB_SERVER_URL}/${context.repository}/compare/${eventData.baseBranch}...?quick_pull=1&title=&body=) + [Create a PR](${GITEA_SERVER_URL}/${context.repository}/compare/${eventData.baseBranch}...?quick_pull=1&title=&body=) - IMPORTANT: Use THREE dots (...) between branch names, not two (..) - Example: ${GITHUB_SERVER_URL}/${context.repository}/compare/main...feature-branch (correct) - NOT: ${GITHUB_SERVER_URL}/${context.repository}/compare/main..feature-branch (incorrect) + Example: ${GITEA_SERVER_URL}/${context.repository}/compare/main...feature-branch (correct) + NOT: ${GITEA_SERVER_URL}/${context.repository}/compare/main..feature-branch (incorrect) - IMPORTANT: Ensure all URL parameters are properly encoded - spaces should be encoded as %20, not left as spaces Example: Instead of "fix: update welcome message", use "fix%3A%20update%20welcome%20message" - The target-branch should be '${eventData.baseBranch}'. diff --git a/src/entrypoints/update-comment-link.ts b/src/entrypoints/update-comment-link.ts index 3ab66d6..8d4e6b4 100644 --- a/src/entrypoints/update-comment-link.ts +++ b/src/entrypoints/update-comment-link.ts @@ -10,7 +10,7 @@ import { parseGitHubContext, isPullRequestReviewCommentEvent, } from "../github/context"; -import { GITHUB_SERVER_URL } from "../github/api/config"; +import { GITEA_SERVER_URL } from "../github/api/config"; import { checkAndDeleteEmptyBranch } from "../github/operations/branch-cleanup"; async function run() { @@ -25,7 +25,7 @@ async function run() { const { owner, repo } = context.repository; const client = createClient(githubToken); - const serverUrl = GITHUB_SERVER_URL; + const serverUrl = GITEA_SERVER_URL; const jobUrl = `${serverUrl}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`; let comment; diff --git a/src/github/api/config.ts b/src/github/api/config.ts index 9e533e5..3c01775 100644 --- a/src/github/api/config.ts +++ b/src/github/api/config.ts @@ -1,4 +1,4 @@ -export const GITHUB_API_URL = - process.env.GITHUB_API_URL || "https://api.github.com"; -export const GITHUB_SERVER_URL = - process.env.GITHUB_SERVER_URL || "https://github.com"; +export const GITEA_API_URL = + process.env.GITEA_API_URL || "https://api.github.com"; +export const GITEA_SERVER_URL = + process.env.GITEA_SERVER_URL || "https://github.com"; diff --git a/src/github/api/gitea-client.ts b/src/github/api/gitea-client.ts index b631ea0..f7c1393 100644 --- a/src/github/api/gitea-client.ts +++ b/src/github/api/gitea-client.ts @@ -1,5 +1,5 @@ import fetch from "node-fetch"; -import { GITHUB_API_URL } from "./config"; +import { GITEA_API_URL } from "./config"; export interface GiteaApiResponse { status: number; @@ -20,7 +20,7 @@ export class GiteaApiClient { private baseUrl: string; private token: string; - constructor(token: string, baseUrl: string = GITHUB_API_URL) { + constructor(token: string, baseUrl: string = GITEA_API_URL) { this.token = token; this.baseUrl = baseUrl.replace(/\/+$/, ""); // Remove trailing slashes } @@ -97,6 +97,11 @@ export class GiteaApiClient { return this.request("GET", `/api/v1/repos/${owner}/${repo}`); } + // Simple test endpoint to verify API connectivity + async testConnection() { + return this.request("GET", "/api/v1/version"); + } + async getBranch(owner: string, repo: string, branch: string) { return this.request("GET", `/api/v1/repos/${owner}/${repo}/branches/${encodeURIComponent(branch)}`); } diff --git a/src/github/operations/branch-cleanup.ts b/src/github/operations/branch-cleanup.ts index ec05e58..c42790d 100644 --- a/src/github/operations/branch-cleanup.ts +++ b/src/github/operations/branch-cleanup.ts @@ -1,5 +1,5 @@ import type { GitHubClient } from "../api/client"; -import { GITHUB_SERVER_URL } from "../api/config"; +import { GITEA_SERVER_URL } from "../api/config"; export async function checkAndDeleteEmptyBranch( client: GitHubClient, @@ -30,7 +30,7 @@ export async function checkAndDeleteEmptyBranch( console.log( `Branch ${claudeBranch} appears to have commits (different SHA from base)`, ); - const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } else { console.log( @@ -51,7 +51,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 = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`; branchLink = `\n[View branch](${branchUrl})`; } } diff --git a/src/github/operations/comment-logic.ts b/src/github/operations/comment-logic.ts index 6a4551a..e0561d0 100644 --- a/src/github/operations/comment-logic.ts +++ b/src/github/operations/comment-logic.ts @@ -1,4 +1,4 @@ -import { GITHUB_SERVER_URL } from "../api/config"; +import { GITEA_SERVER_URL } from "../api/config"; export type ExecutionDetails = { cost_usd?: number; @@ -160,7 +160,7 @@ export function updateCommentBody(input: CommentUpdateInput): string { // Extract owner/repo from jobUrl const repoMatch = jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//); if (repoMatch) { - branchUrl = `${GITHUB_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`; + branchUrl = `${GITEA_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`; } } diff --git a/src/github/operations/comments/common.ts b/src/github/operations/comments/common.ts index df24c03..37bf6a1 100644 --- a/src/github/operations/comments/common.ts +++ b/src/github/operations/comments/common.ts @@ -1,4 +1,4 @@ -import { GITHUB_SERVER_URL } from "../../api/config"; +import { GITEA_SERVER_URL } from "../../api/config"; export const SPINNER_HTML = ''; @@ -8,7 +8,7 @@ export function createJobRunLink( repo: string, runId: string, ): string { - const jobRunUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${runId}`; + const jobRunUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/actions/runs/${runId}`; return `[View job run](${jobRunUrl})`; } @@ -17,7 +17,7 @@ export function createBranchLink( repo: string, branchName: string, ): string { - const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${branchName}`; + const branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/tree/${branchName}`; return `\n[View branch](${branchUrl})`; } diff --git a/src/github/operations/comments/create-initial.ts b/src/github/operations/comments/create-initial.ts index e5d032d..5f74b7c 100644 --- a/src/github/operations/comments/create-initial.ts +++ b/src/github/operations/comments/create-initial.ts @@ -26,6 +26,7 @@ export async function createInitialComment( let response; console.log(`Creating comment for ${context.isPR ? 'PR' : 'issue'} #${context.entityNumber}`); + console.log(`Repository: ${owner}/${repo}`); // Only use createReplyForReviewComment if it's a PR review comment AND we have a comment_id if (isPullRequestReviewCommentEvent(context)) { diff --git a/src/github/validation/actor.ts b/src/github/validation/actor.ts index 787c513..d38c7c3 100644 --- a/src/github/validation/actor.ts +++ b/src/github/validation/actor.ts @@ -14,8 +14,8 @@ export async function checkHumanActor( ) { // Check if we're in a Gitea environment const isGitea = - process.env.GITHUB_API_URL && - !process.env.GITHUB_API_URL.includes("api.github.com"); + process.env.GITEA_API_URL && + !process.env.GITEA_API_URL.includes("api.github.com"); if (isGitea) { console.log( diff --git a/src/github/validation/permissions.ts b/src/github/validation/permissions.ts index b219736..e3652b2 100644 --- a/src/github/validation/permissions.ts +++ b/src/github/validation/permissions.ts @@ -16,8 +16,8 @@ export async function checkWritePermissions( // For Gitea compatibility, check if we're in a non-GitHub environment const isGitea = - process.env.GITHUB_API_URL && - !process.env.GITHUB_API_URL.includes("api.github.com"); + process.env.GITEA_API_URL && + !process.env.GITEA_API_URL.includes("api.github.com"); if (isGitea) { core.info(`Detected Gitea environment, assuming actor has permissions`); diff --git a/src/mcp/github-file-ops-server.ts b/src/mcp/github-file-ops-server.ts index 04567e8..4f74255 100644 --- a/src/mcp/github-file-ops-server.ts +++ b/src/mcp/github-file-ops-server.ts @@ -6,7 +6,7 @@ import { z } from "zod"; import { readFile } from "fs/promises"; import { join } from "path"; import fetch from "node-fetch"; -import { GITHUB_API_URL } from "../github/api/config"; +import { GITEA_API_URL } from "../github/api/config"; type GitHubRef = { object: { diff --git a/test/branch-cleanup.test.ts b/test/branch-cleanup.test.ts index 488bce8..5ddf241 100644 --- a/test/branch-cleanup.test.ts +++ b/test/branch-cleanup.test.ts @@ -1,7 +1,7 @@ import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test"; import { checkAndDeleteEmptyBranch } from "../src/github/operations/branch-cleanup"; import type { Octokits } from "../src/github/api/client"; -import { GITHUB_SERVER_URL } from "../src/github/api/config"; +import { GITEA_SERVER_URL } from "../src/github/api/config"; describe("checkAndDeleteEmptyBranch", () => { let consoleLogSpy: any; @@ -88,7 +88,7 @@ describe("checkAndDeleteEmptyBranch", () => { expect(result.shouldDeleteBranch).toBe(false); expect(result.branchLink).toBe( - `\n[View branch](${GITHUB_SERVER_URL}/owner/repo/tree/claude/issue-123-20240101_123456)`, + `\n[View branch](${GITEA_SERVER_URL}/owner/repo/tree/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](${GITHUB_SERVER_URL}/owner/repo/tree/claude/issue-123-20240101_123456)`, + `\n[View branch](${GITEA_SERVER_URL}/owner/repo/tree/claude/issue-123-20240101_123456)`, ); expect(consoleErrorSpy).toHaveBeenCalledWith( "Error checking for commits on Claude branch:",