simplify createBranchUrl

This commit is contained in:
Anonymous 2026-01-29 23:05:52 +08:00
parent 7904dcc331
commit e5ee232989
3 changed files with 9 additions and 27 deletions

View File

@ -81,9 +81,7 @@ export async function checkAndCommitOrDeleteBranch(
);
// Set branch link since we now have commits
const branchUrl = USE_GITEA_API
? createBranchUrl(owner, repo, claudeBranch)
: `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
const branchUrl = createBranchUrl(owner, repo, claudeBranch);
branchLink = `\n[View branch](${branchUrl})`;
} else {
console.log(
@ -94,9 +92,7 @@ export async function checkAndCommitOrDeleteBranch(
} catch (gitError) {
console.error("Error checking/committing changes:", gitError);
// If we can't check git status, assume the branch might have changes
const branchUrl = USE_GITEA_API
? createBranchUrl(owner, repo, claudeBranch)
: `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
const branchUrl = createBranchUrl(owner, repo, claudeBranch);
branchLink = `\n[View branch](${branchUrl})`;
}
} else {
@ -107,17 +103,13 @@ export async function checkAndCommitOrDeleteBranch(
}
} else {
// Only add branch link if there are commits
const branchUrl = USE_GITEA_API
? createBranchUrl(owner, repo, claudeBranch)
: `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
const branchUrl = createBranchUrl(owner, repo, claudeBranch);
branchLink = `\n[View branch](${branchUrl})`;
}
} catch (error) {
console.error("Error comparing commits on Claude branch:", error);
// If we can't compare but the branch exists remotely, include the branch link
const branchUrl = USE_GITEA_API
? createBranchUrl(owner, repo, claudeBranch)
: `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${claudeBranch}`;
const branchUrl = createBranchUrl(owner, repo, claudeBranch);
branchLink = `\n[View branch](${branchUrl})`;
}
}

View File

@ -163,9 +163,7 @@ export function updateCommentBody(input: CommentUpdateInput): string {
? jobUrl.match(/\/([^\/]+)\/([^\/]+)\/(?:actions|tree|src)/)
: jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//);
if (repoMatch) {
branchUrl = USE_GITEA_API
? createBranchUrl(repoMatch[1], repoMatch[2], finalBranchName)
: `${GITHUB_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/tree/${finalBranchName}`;
branchUrl = createBranchUrl(repoMatch[1], repoMatch[2], finalBranchName);
}
}

View File

@ -17,20 +17,10 @@ export function createBranchLink(
repo: string,
branchName: string,
): string {
const branchUrl = USE_GITEA_API
? createBranchUrl(owner, repo, branchName)
: `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${branchName}`;
const branchUrl = createBranchUrl(owner, repo, branchName);
return `\n[View branch](${branchUrl})`;
}
/**
* Get the branch URL path segment for the current platform
* Gitea uses /src/branch/ while GitHub uses /tree/
*/
export function getBranchPath(): string {
return USE_GITEA_API ? "src/branch" : "tree";
}
/**
* Create a branch URL for the current platform
*/
@ -39,7 +29,9 @@ export function createBranchUrl(
repo: string,
branchName: string,
): string {
return `${GITHUB_SERVER_URL}/${owner}/${repo}/${getBranchPath()}/${branchName}`;
return USE_GITEA_API
? `${GITHUB_SERVER_URL}/${owner}/${repo}/src/branch/${branchName}`
: `${GITHUB_SERVER_URL}/${owner}/${repo}/tree/${branchName}`;
}
export function createCommentBody(