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:
@@ -155,10 +155,21 @@ async function run() {
|
||||
`Branch ${claudeBranch} has same SHA as base, no PR link needed`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error("Error checking branch in Gitea:", error);
|
||||
// If we can't check in Gitea, add PR link to be safe
|
||||
console.log("Adding PR link as fallback for Gitea");
|
||||
|
||||
// Handle 404 specifically - branch doesn't exist
|
||||
if (error.status === 404) {
|
||||
console.log(
|
||||
`Branch ${claudeBranch} does not exist yet - no PR link needed`,
|
||||
);
|
||||
// Don't add PR link since branch doesn't exist
|
||||
prLink = "";
|
||||
} else {
|
||||
// For other errors, add PR link to be safe
|
||||
console.log(
|
||||
"Adding PR link as fallback for Gitea due to non-404 error",
|
||||
);
|
||||
const entityType = context.isPR ? "PR" : "Issue";
|
||||
const prTitle = encodeURIComponent(
|
||||
`${entityType} #${context.entityNumber}: Changes from Claude`,
|
||||
@@ -169,6 +180,7 @@ async function run() {
|
||||
const prUrl = `${serverUrl}/${owner}/${repo}/compare/${baseBranch}...${claudeBranch}?quick_pull=1&title=${prTitle}&body=${prBody}`;
|
||||
prLink = `\n[Create a PR](${prUrl})`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// GitHub environment - use the comparison API
|
||||
try {
|
||||
|
||||
@@ -54,12 +54,23 @@ export async function checkAndDeleteEmptyBranch(
|
||||
);
|
||||
shouldDeleteBranch = true;
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error("Error checking branch in Gitea:", error);
|
||||
// If we can't check, assume the branch has commits to be safe
|
||||
|
||||
// Handle 404 specifically - branch doesn't exist
|
||||
if (error.status === 404) {
|
||||
console.log(
|
||||
`Branch ${claudeBranch} does not exist yet - this is normal during workflow`,
|
||||
);
|
||||
// Don't add branch link since branch doesn't exist
|
||||
branchLink = "";
|
||||
} 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}`;
|
||||
branchLink = `\n[View branch](${branchUrl})`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// GitHub environment - use the comparison API
|
||||
try {
|
||||
|
||||
@@ -121,21 +121,39 @@ export async function setupBranch(
|
||||
|
||||
console.log(`Current SHA: ${currentSHA}`);
|
||||
|
||||
// Check if we're in a Gitea environment
|
||||
// Try to create branch using the appropriate method for each platform
|
||||
const isGitea =
|
||||
process.env.GITHUB_API_URL &&
|
||||
!process.env.GITHUB_API_URL.includes("api.github.com");
|
||||
|
||||
if (isGitea) {
|
||||
// Gitea doesn't reliably support git.createRef, skip it
|
||||
// Gitea supports POST /repos/{owner}/{repo}/branches
|
||||
console.log(
|
||||
`Detected Gitea environment, skipping git.createRef for branch: ${newBranch}`,
|
||||
`Detected Gitea environment, using branches API for: ${newBranch}`,
|
||||
);
|
||||
|
||||
try {
|
||||
// Use the raw Gitea API since Octokit might not have the createBranch method
|
||||
await octokits.rest.request("POST /repos/{owner}/{repo}/branches", {
|
||||
owner,
|
||||
repo,
|
||||
new_branch_name: newBranch,
|
||||
old_branch_name: sourceBranch,
|
||||
});
|
||||
console.log(
|
||||
`Successfully created branch via Gitea branches API: ${newBranch}`,
|
||||
);
|
||||
} catch (createBranchError: any) {
|
||||
console.log(
|
||||
`Gitea branch creation failed: ${createBranchError.message}`,
|
||||
);
|
||||
console.log(`Error status: ${createBranchError.status}`);
|
||||
console.log(
|
||||
`Branch ${newBranch} will be created when files are pushed via MCP server`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// GitHub environment - try to create branch via API
|
||||
// GitHub environment - use git.createRef
|
||||
try {
|
||||
await octokits.rest.git.createRef({
|
||||
owner,
|
||||
@@ -144,12 +162,11 @@ export async function setupBranch(
|
||||
sha: currentSHA,
|
||||
});
|
||||
|
||||
console.log(`Successfully created branch via API: ${newBranch}`);
|
||||
} catch (createRefError: any) {
|
||||
// If creation fails on GitHub, log but continue
|
||||
console.log(
|
||||
`git createRef failed on GitHub: ${createRefError.message}`,
|
||||
`Successfully created branch via GitHub git.createRef: ${newBranch}`,
|
||||
);
|
||||
} catch (createRefError: any) {
|
||||
console.log(`GitHub git.createRef failed: ${createRefError.message}`);
|
||||
console.log(`Error status: ${createRefError.status}`);
|
||||
console.log(
|
||||
`Branch ${newBranch} will be created when files are pushed`,
|
||||
|
||||
Reference in New Issue
Block a user