mirror of
https://github.com/markwylde/claude-code-gitea-action.git
synced 2026-02-20 02:22:49 +08:00
Attempt to make this work
This commit is contained in:
@@ -19,7 +19,7 @@ import {
|
|||||||
} from "../github/context";
|
} from "../github/context";
|
||||||
import type { ParsedGitHubContext } from "../github/context";
|
import type { ParsedGitHubContext } from "../github/context";
|
||||||
import type { CommonFields, PreparedContext, EventData } from "./types";
|
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";
|
export type { CommonFields, PreparedContext } from "./types";
|
||||||
|
|
||||||
const BASE_ALLOWED_TOOLS = [
|
const BASE_ALLOWED_TOOLS = [
|
||||||
@@ -541,10 +541,10 @@ ${context.directPrompt ? ` - DIRECT INSTRUCTION: A direct instruction was prov
|
|||||||
${
|
${
|
||||||
eventData.claudeBranch
|
eventData.claudeBranch
|
||||||
? `- Provide a URL to create a PR manually in this format:
|
? `- 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 (..)
|
- IMPORTANT: Use THREE dots (...) between branch names, not two (..)
|
||||||
Example: ${GITHUB_SERVER_URL}/${context.repository}/compare/main...feature-branch (correct)
|
Example: ${GITEA_SERVER_URL}/${context.repository}/compare/main...feature-branch (correct)
|
||||||
NOT: ${GITHUB_SERVER_URL}/${context.repository}/compare/main..feature-branch (incorrect)
|
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
|
- 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"
|
Example: Instead of "fix: update welcome message", use "fix%3A%20update%20welcome%20message"
|
||||||
- The target-branch should be '${eventData.baseBranch}'.
|
- The target-branch should be '${eventData.baseBranch}'.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
parseGitHubContext,
|
parseGitHubContext,
|
||||||
isPullRequestReviewCommentEvent,
|
isPullRequestReviewCommentEvent,
|
||||||
} from "../github/context";
|
} 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";
|
import { checkAndDeleteEmptyBranch } from "../github/operations/branch-cleanup";
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
@@ -25,7 +25,7 @@ async function run() {
|
|||||||
const { owner, repo } = context.repository;
|
const { owner, repo } = context.repository;
|
||||||
const client = createClient(githubToken);
|
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}`;
|
const jobUrl = `${serverUrl}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
|
||||||
|
|
||||||
let comment;
|
let comment;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const GITHUB_API_URL =
|
export const GITEA_API_URL =
|
||||||
process.env.GITHUB_API_URL || "https://api.github.com";
|
process.env.GITEA_API_URL || "https://api.github.com";
|
||||||
export const GITHUB_SERVER_URL =
|
export const GITEA_SERVER_URL =
|
||||||
process.env.GITHUB_SERVER_URL || "https://github.com";
|
process.env.GITEA_SERVER_URL || "https://github.com";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { GITHUB_API_URL } from "./config";
|
import { GITEA_API_URL } from "./config";
|
||||||
|
|
||||||
export interface GiteaApiResponse<T = any> {
|
export interface GiteaApiResponse<T = any> {
|
||||||
status: number;
|
status: number;
|
||||||
@@ -20,7 +20,7 @@ export class GiteaApiClient {
|
|||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
private token: string;
|
private token: string;
|
||||||
|
|
||||||
constructor(token: string, baseUrl: string = GITHUB_API_URL) {
|
constructor(token: string, baseUrl: string = GITEA_API_URL) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.baseUrl = baseUrl.replace(/\/+$/, ""); // Remove trailing slashes
|
this.baseUrl = baseUrl.replace(/\/+$/, ""); // Remove trailing slashes
|
||||||
}
|
}
|
||||||
@@ -97,6 +97,11 @@ export class GiteaApiClient {
|
|||||||
return this.request("GET", `/api/v1/repos/${owner}/${repo}`);
|
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) {
|
async getBranch(owner: string, repo: string, branch: string) {
|
||||||
return this.request("GET", `/api/v1/repos/${owner}/${repo}/branches/${encodeURIComponent(branch)}`);
|
return this.request("GET", `/api/v1/repos/${owner}/${repo}/branches/${encodeURIComponent(branch)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { GitHubClient } from "../api/client";
|
import type { GitHubClient } from "../api/client";
|
||||||
import { GITHUB_SERVER_URL } from "../api/config";
|
import { GITEA_SERVER_URL } from "../api/config";
|
||||||
|
|
||||||
export async function checkAndDeleteEmptyBranch(
|
export async function checkAndDeleteEmptyBranch(
|
||||||
client: GitHubClient,
|
client: GitHubClient,
|
||||||
@@ -30,7 +30,7 @@ export async function checkAndDeleteEmptyBranch(
|
|||||||
console.log(
|
console.log(
|
||||||
`Branch ${claudeBranch} appears to have commits (different SHA from base)`,
|
`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})`;
|
branchLink = `\n[View branch](${branchUrl})`;
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -51,7 +51,7 @@ export async function checkAndDeleteEmptyBranch(
|
|||||||
} else {
|
} else {
|
||||||
// For other errors, assume the branch has commits to be safe
|
// For other errors, assume the branch has commits to be safe
|
||||||
console.log("Assuming branch exists due to non-404 error");
|
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})`;
|
branchLink = `\n[View branch](${branchUrl})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GITHUB_SERVER_URL } from "../api/config";
|
import { GITEA_SERVER_URL } from "../api/config";
|
||||||
|
|
||||||
export type ExecutionDetails = {
|
export type ExecutionDetails = {
|
||||||
cost_usd?: number;
|
cost_usd?: number;
|
||||||
@@ -160,7 +160,7 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
|||||||
// Extract owner/repo from jobUrl
|
// Extract owner/repo from jobUrl
|
||||||
const repoMatch = jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//);
|
const repoMatch = jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//);
|
||||||
if (repoMatch) {
|
if (repoMatch) {
|
||||||
branchUrl = `${GITHUB_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`;
|
branchUrl = `${GITEA_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GITHUB_SERVER_URL } from "../../api/config";
|
import { GITEA_SERVER_URL } from "../../api/config";
|
||||||
|
|
||||||
export const SPINNER_HTML =
|
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;" />';
|
'<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,
|
repo: string,
|
||||||
runId: string,
|
runId: string,
|
||||||
): 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})`;
|
return `[View job run](${jobRunUrl})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ export function createBranchLink(
|
|||||||
repo: string,
|
repo: string,
|
||||||
branchName: string,
|
branchName: string,
|
||||||
): 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})`;
|
return `\n[View branch](${branchUrl})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export async function createInitialComment(
|
|||||||
let response;
|
let response;
|
||||||
|
|
||||||
console.log(`Creating comment for ${context.isPR ? 'PR' : 'issue'} #${context.entityNumber}`);
|
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
|
// Only use createReplyForReviewComment if it's a PR review comment AND we have a comment_id
|
||||||
if (isPullRequestReviewCommentEvent(context)) {
|
if (isPullRequestReviewCommentEvent(context)) {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ export async function checkHumanActor(
|
|||||||
) {
|
) {
|
||||||
// Check if we're in a Gitea environment
|
// Check if we're in a Gitea environment
|
||||||
const isGitea =
|
const isGitea =
|
||||||
process.env.GITHUB_API_URL &&
|
process.env.GITEA_API_URL &&
|
||||||
!process.env.GITHUB_API_URL.includes("api.github.com");
|
!process.env.GITEA_API_URL.includes("api.github.com");
|
||||||
|
|
||||||
if (isGitea) {
|
if (isGitea) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export async function checkWritePermissions(
|
|||||||
|
|
||||||
// For Gitea compatibility, check if we're in a non-GitHub environment
|
// For Gitea compatibility, check if we're in a non-GitHub environment
|
||||||
const isGitea =
|
const isGitea =
|
||||||
process.env.GITHUB_API_URL &&
|
process.env.GITEA_API_URL &&
|
||||||
!process.env.GITHUB_API_URL.includes("api.github.com");
|
!process.env.GITEA_API_URL.includes("api.github.com");
|
||||||
|
|
||||||
if (isGitea) {
|
if (isGitea) {
|
||||||
core.info(`Detected Gitea environment, assuming actor has permissions`);
|
core.info(`Detected Gitea environment, assuming actor has permissions`);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { z } from "zod";
|
|||||||
import { readFile } from "fs/promises";
|
import { readFile } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { GITHUB_API_URL } from "../github/api/config";
|
import { GITEA_API_URL } from "../github/api/config";
|
||||||
|
|
||||||
type GitHubRef = {
|
type GitHubRef = {
|
||||||
object: {
|
object: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
||||||
import { checkAndDeleteEmptyBranch } from "../src/github/operations/branch-cleanup";
|
import { checkAndDeleteEmptyBranch } from "../src/github/operations/branch-cleanup";
|
||||||
import type { Octokits } from "../src/github/api/client";
|
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", () => {
|
describe("checkAndDeleteEmptyBranch", () => {
|
||||||
let consoleLogSpy: any;
|
let consoleLogSpy: any;
|
||||||
@@ -88,7 +88,7 @@ describe("checkAndDeleteEmptyBranch", () => {
|
|||||||
|
|
||||||
expect(result.shouldDeleteBranch).toBe(false);
|
expect(result.shouldDeleteBranch).toBe(false);
|
||||||
expect(result.branchLink).toBe(
|
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(consoleLogSpy).not.toHaveBeenCalledWith(
|
||||||
expect.stringContaining("has no commits"),
|
expect.stringContaining("has no commits"),
|
||||||
@@ -119,7 +119,7 @@ describe("checkAndDeleteEmptyBranch", () => {
|
|||||||
|
|
||||||
expect(result.shouldDeleteBranch).toBe(false);
|
expect(result.shouldDeleteBranch).toBe(false);
|
||||||
expect(result.branchLink).toBe(
|
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(
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||||
"Error checking for commits on Claude branch:",
|
"Error checking for commits on Claude branch:",
|
||||||
|
|||||||
Reference in New Issue
Block a user