- Removed unused re-exports (CommentUpdateInput, ExecutionDetails, ensureProperlyEncodedUrl) from forgejo/comment-logic.ts - Verified no `any` type escapes in Forgejo-specific code - Confirmed naming conventions consistent with upstream - No dead code, unused imports, or unreachable branches - All complex decisions documented with comments - Typecheck, format, and 834 tests pass clean Progress: 83% complete — M6 (documentation accuracy) remaining Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
105 lines
3.6 KiB
TypeScript
105 lines
3.6 KiB
TypeScript
/**
|
|
* Forgejo-specific comment URL formatting and body construction.
|
|
*
|
|
* Contains Forgejo-specific helpers for:
|
|
* - Unicode spinner instead of GitHub CDN image (CDN URLs don't resolve on Forgejo)
|
|
* - PR compare URL with `expand=1` instead of GitHub's `quick_pull=1`
|
|
* - Forgejo run index (GITHUB_RUN_NUMBER vs GITHUB_RUN_ID)
|
|
*
|
|
* The final comment body logic (updateCommentBody) is unified in
|
|
* src/github/operations/comment-logic.ts and works for both platforms.
|
|
*/
|
|
|
|
import { getServerUrl } from "../github/api/config";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Run index helper
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Get the run identifier for Forgejo URLs.
|
|
*
|
|
* Forgejo uses the per-repo sequential run index in URLs (`/actions/runs/{index}`),
|
|
* not the internal database run ID. The Forgejo runner sets:
|
|
* - GITHUB_RUN_ID = internal DB primary key (e.g. 11943)
|
|
* - GITHUB_RUN_NUMBER = per-repo sequential index (e.g. 661)
|
|
*
|
|
* GitHub uses GITHUB_RUN_ID in URLs, but Forgejo uses GITHUB_RUN_NUMBER.
|
|
*/
|
|
export function getForgejoRunIndex(): string {
|
|
return process.env.GITHUB_RUN_NUMBER || process.env.GITHUB_RUN_ID || "0";
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Spinner
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Unicode spinner for Forgejo comments.
|
|
* The GitHub version uses a CDN-hosted animated GIF that won't load on Forgejo.
|
|
*/
|
|
export const FORGEJO_SPINNER_HTML = "⏳";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// URL Builders
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Note: owner, repo, runId, and branchName are NOT URI-encoded in path
|
|
// segments because: (1) owner/repo are validated by Forgejo (alphanumeric +
|
|
// .-_), (2) branchName is validated by validateBranchName() which restricts
|
|
// to [a-zA-Z0-9._/-], and (3) encoding "/" in branch names breaks Forgejo
|
|
// URLs (e.g., "claude/fix-bug" → "claude%2Ffix-bug" is invalid).
|
|
|
|
export function createForgejoJobRunLink(
|
|
owner: string,
|
|
repo: string,
|
|
runId: string,
|
|
): string {
|
|
const jobRunUrl = `${getServerUrl()}/${owner}/${repo}/actions/runs/${runId}`;
|
|
return `[View job run](${jobRunUrl})`;
|
|
}
|
|
|
|
export function createForgejoBranchLink(
|
|
owner: string,
|
|
repo: string,
|
|
branchName: string,
|
|
): string {
|
|
const branchUrl = `${getServerUrl()}/${owner}/${repo}/tree/${branchName}`;
|
|
return `\n[View branch](${branchUrl})`;
|
|
}
|
|
|
|
/**
|
|
* Build a Forgejo PR compare URL for "Create a PR" links.
|
|
*
|
|
* Forgejo's compare page pre-fills title/body from query params but does not
|
|
* support GitHub's `quick_pull=1` parameter.
|
|
*/
|
|
export function createForgejoPrCompareUrl(
|
|
serverUrl: string,
|
|
owner: string,
|
|
repo: string,
|
|
baseBranch: string,
|
|
headBranch: string,
|
|
title: string,
|
|
body: string,
|
|
): string {
|
|
const prTitle = encodeURIComponent(title);
|
|
const prBody = encodeURIComponent(body);
|
|
return `${serverUrl}/${owner}/${repo}/compare/${baseBranch}...${headBranch}?expand=1&title=${prTitle}&body=${prBody}`;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Initial comment body (shown while Claude is working)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function createForgejoCommentBody(
|
|
jobRunLink: string,
|
|
branchLink: string = "",
|
|
): string {
|
|
return `Claude Code is working… ${FORGEJO_SPINNER_HTML}
|
|
|
|
I'll analyze this and get back to you.
|
|
|
|
${jobRunLink}${branchLink}`;
|
|
}
|