Attempt to make this work

This commit is contained in:
Mark Wylde
2025-05-30 22:11:20 +01:00
parent 87c1a97c6e
commit 11685fc8c1
12 changed files with 34 additions and 28 deletions

View File

@@ -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}...<branch-name>?quick_pull=1&title=<url-encoded-title>&body=<url-encoded-body>)
[Create a PR](${GITEA_SERVER_URL}/${context.repository}/compare/${eventData.baseBranch}...<branch-name>?quick_pull=1&title=<url-encoded-title>&body=<url-encoded-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}'.

View File

@@ -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;

View File

@@ -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";

View File

@@ -1,5 +1,5 @@
import fetch from "node-fetch";
import { GITHUB_API_URL } from "./config";
import { GITEA_API_URL } from "./config";
export interface GiteaApiResponse<T = any> {
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)}`);
}

View File

@@ -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})`;
}
}

View File

@@ -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}`;
}
}

View File

@@ -1,4 +1,4 @@
import { GITHUB_SERVER_URL } from "../../api/config";
import { GITEA_SERVER_URL } from "../../api/config";
export const SPINNER_HTML =
'<img src="https://github.com/user-attachments/assets/5ac382c7-e004-429b-8e35-7feb3e8f9c6f" width="14px" height="14px" style="vertical-align: middle; margin-left: 4px;" />';
@@ -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})`;
}

View File

@@ -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)) {

View File

@@ -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(

View File

@@ -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`);

View File

@@ -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: {

View File

@@ -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:",