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,19 +155,31 @@ async function run() {
|
|||||||
`Branch ${claudeBranch} has same SHA as base, no PR link needed`,
|
`Branch ${claudeBranch} has same SHA as base, no PR link needed`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error("Error checking branch in Gitea:", error);
|
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
|
||||||
const entityType = context.isPR ? "PR" : "Issue";
|
if (error.status === 404) {
|
||||||
const prTitle = encodeURIComponent(
|
console.log(
|
||||||
`${entityType} #${context.entityNumber}: Changes from Claude`,
|
`Branch ${claudeBranch} does not exist yet - no PR link needed`,
|
||||||
);
|
);
|
||||||
const prBody = encodeURIComponent(
|
// Don't add PR link since branch doesn't exist
|
||||||
`This PR addresses ${entityType.toLowerCase()} #${context.entityNumber}\n\nGenerated with [Claude Code](https://claude.ai/code)`,
|
prLink = "";
|
||||||
);
|
} else {
|
||||||
const prUrl = `${serverUrl}/${owner}/${repo}/compare/${baseBranch}...${claudeBranch}?quick_pull=1&title=${prTitle}&body=${prBody}`;
|
// For other errors, add PR link to be safe
|
||||||
prLink = `\n[Create a PR](${prUrl})`;
|
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`,
|
||||||
|
);
|
||||||
|
const prBody = encodeURIComponent(
|
||||||
|
`This PR addresses ${entityType.toLowerCase()} #${context.entityNumber}\n\nGenerated with [Claude Code](https://claude.ai/code)`,
|
||||||
|
);
|
||||||
|
const prUrl = `${serverUrl}/${owner}/${repo}/compare/${baseBranch}...${claudeBranch}?quick_pull=1&title=${prTitle}&body=${prBody}`;
|
||||||
|
prLink = `\n[Create a PR](${prUrl})`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// GitHub environment - use the comparison API
|
// GitHub environment - use the comparison API
|
||||||
|
|||||||
@@ -54,11 +54,22 @@ export async function checkAndDeleteEmptyBranch(
|
|||||||
);
|
);
|
||||||
shouldDeleteBranch = true;
|
shouldDeleteBranch = true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error("Error checking branch in Gitea:", error);
|
console.error("Error checking branch in Gitea:", error);
|
||||||
// If we can't check, assume the branch has commits to be safe
|
|
||||||
const branchUrl = `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
|
// Handle 404 specifically - branch doesn't exist
|
||||||
branchLink = `\n[View branch](${branchUrl})`;
|
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 {
|
} else {
|
||||||
// GitHub environment - use the comparison API
|
// GitHub environment - use the comparison API
|
||||||
|
|||||||
@@ -121,21 +121,39 @@ export async function setupBranch(
|
|||||||
|
|
||||||
console.log(`Current SHA: ${currentSHA}`);
|
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 =
|
const isGitea =
|
||||||
process.env.GITHUB_API_URL &&
|
process.env.GITHUB_API_URL &&
|
||||||
!process.env.GITHUB_API_URL.includes("api.github.com");
|
!process.env.GITHUB_API_URL.includes("api.github.com");
|
||||||
|
|
||||||
if (isGitea) {
|
if (isGitea) {
|
||||||
// Gitea doesn't reliably support git.createRef, skip it
|
// Gitea supports POST /repos/{owner}/{repo}/branches
|
||||||
console.log(
|
console.log(
|
||||||
`Detected Gitea environment, skipping git.createRef for branch: ${newBranch}`,
|
`Detected Gitea environment, using branches API for: ${newBranch}`,
|
||||||
);
|
|
||||||
console.log(
|
|
||||||
`Branch ${newBranch} will be created when files are pushed via MCP server`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
// GitHub environment - try to create branch via API
|
// GitHub environment - use git.createRef
|
||||||
try {
|
try {
|
||||||
await octokits.rest.git.createRef({
|
await octokits.rest.git.createRef({
|
||||||
owner,
|
owner,
|
||||||
@@ -144,12 +162,11 @@ export async function setupBranch(
|
|||||||
sha: currentSHA,
|
sha: currentSHA,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Successfully created branch via API: ${newBranch}`);
|
|
||||||
} catch (createRefError: any) {
|
|
||||||
// If creation fails on GitHub, log but continue
|
|
||||||
console.log(
|
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(`Error status: ${createRefError.status}`);
|
||||||
console.log(
|
console.log(
|
||||||
`Branch ${newBranch} will be created when files are pushed`,
|
`Branch ${newBranch} will be created when files are pushed`,
|
||||||
|
|||||||
Reference in New Issue
Block a user