fix(prd-7): M1 architecture review — consolidate duplication, fix bugs, memoize detection

- F1: Consolidated updateForgejoCommentBody into unified updateCommentBody (~150 lines removed)
- F2: Fixed wrong run identifier in update-with-branch.ts (context.runId → getForgejoRunIndex())
- F3: Memoized detectPlatform() with _resetPlatformCache() for tests
- F4: Added getServerUrl() runtime helper to resolve constant-vs-function inconsistency
- F5: Fixed sticky comment bot matching on Forgejo via context.inputs.botName
- F6: Documented GHES heuristic misidentification in docs/forgejo.md
- Updated PRD M1 checkbox to complete

Progress: 17% complete — M1 done, M2 (error handling review) next

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vlad MocanuandClaude Opus 4.6 committed 2026-02-26 12:09:02 +02:00
1 parent ae326659b1
commit ac58fb6c14
15 files changed
+151 -266

No files matched your search

+32 -9
View File
@@ -6,24 +6,47 @@
* 2. FORGEJO env var (set by Forgejo runner v7.0+)
* 3. GITHUB_SERVER_URL heuristic (non-github.com = Forgejo)
* 4. Default to GitHub
*
* The result is memoized after first detection — platform doesn't change
* at runtime and this avoids redundant env reads across 12+ call sites.
*/
export type Platform = "github" | "forgejo";
let _cachedPlatform: Platform | undefined;
export function detectPlatform(): Platform {
if (_cachedPlatform !== undefined) return _cachedPlatform;
let result: Platform = "github";
// 1. Explicit platform from action.yml detect step or user input
const platformEnv = process.env.PLATFORM;
if (platformEnv === "forgejo") return "forgejo";
if (platformEnv === "github") return "github";
if (platformEnv === "forgejo") {
result = "forgejo";
} else if (platformEnv === "github") {
result = "github";
}
// 2. FORGEJO env var (set by Forgejo runner v7.0+)
if (process.env.FORGEJO === "true") return "forgejo";
else if (process.env.FORGEJO === "true") {
result = "forgejo";
}
// 3. GITHUB_SERVER_URL heuristic — if not github.com, likely Forgejo/Gitea
const serverUrl = process.env.GITHUB_SERVER_URL || "";
if (serverUrl && !serverUrl.includes("github.com")) {
return "forgejo";
else {
const serverUrl = process.env.GITHUB_SERVER_URL || "";
if (serverUrl && !serverUrl.includes("github.com")) {
result = "forgejo";
}
}
return "github";
_cachedPlatform = result;
return result;
}
/**
* Reset the memoized platform detection result.
* Only needed in tests that change platform-related env vars between cases.
*/
export function _resetPlatformCache(): void {
_cachedPlatform = undefined;
}