Skip to content

fix: improve API error handling and add ARM architecture detection#17

Merged
ccsert merged 1 commit into
mainfrom
fix/issue-12-14-api-url-and-arm
May 21, 2026
Merged

fix: improve API error handling and add ARM architecture detection#17
ccsert merged 1 commit into
mainfrom
fix/issue-12-14-api-url-and-arm

Conversation

@ccsert
Copy link
Copy Markdown
Owner

@ccsert ccsert commented Apr 30, 2026

Summary

  • Fixes commenting on issues does not work #12: Improve Gitea API error handling. Add URL normalization (normalizeBaseUrl) to handle trailing slashes and /api/v1 suffix in GITEA_SERVER_URL. Add detailed 404 error messages with troubleshooting hints to help users diagnose misconfiguration.
  • Fixes Fails on rpi4 #14: Add ARM architecture detection. The opencode-ai binary only supports x86_64/amd64. Now the Dockerfile shows a build-time warning, and the entrypoint checks at runtime whether the binary actually works on non-x86 architectures, with a clear error message pointing users to the source installation method.

Changes

File Change
gitea-pr-diff.ts Add normalizeBaseUrl() + improved 404 error
gitea-pr-files.ts Add normalizeBaseUrl() + improved 404 error
gitea-review.ts Add normalizeBaseUrl() + improved 404 error
gitea-comment.ts Add normalizeBaseUrl() + improved 404 error
gitea-incremental-diff.ts Add normalizeBaseUrl() + improved 404 error
entrypoint.sh Add check_architecture() function; normalize URL in infer_gitea_server_url()
Dockerfile Add build-time architecture warning
README.md / README_zh.md Document x86_64-only Docker support

Root Cause Analysis

Issue #12: The error URL https://gitea-hosted.com/api/swagger in the 404 response is Gitea's default error format — it's NOT generated by our code. The actual API request likely fails due to GITEA_SERVER_URL having trailing slashes (e.g., https://host.com/https://host.com//api/v1/...) or including /api/v1 already.

Issue #14: opencode-ai ships a pre-compiled binary (.opencode) that only supports x86_64. On ARM platforms, it fails with glibc symbol errors. This is an upstream limitation.

Closes #12, Closes #14

- Add URL normalization in giteaFetch to handle trailing slashes and /api/v1 suffix
- Add detailed 404 error messages with troubleshooting hints (fixes #12)
- Add architecture detection in Dockerfile and entrypoint.sh (fixes #14)
- Graceful error when opencode binary incompatible with ARM
- Document x86_64-only Docker support in README
Copilot AI review requested due to automatic review settings April 30, 2026 08:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the reliability and diagnosability of the Gitea/Forgejo integration by normalizing the configured server base URL (avoiding double /api/v1 and trailing slash issues) and adds clearer ARM/x86_64 architecture handling for the Docker-based installation path.

Changes:

  • Add base URL normalization in all Gitea API tools and provide a more actionable 404 error message.
  • Add runtime architecture checking in entrypoint.sh plus a build-time warning in the Dockerfile.
  • Document x86_64-only Docker support in English and Chinese READMEs.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
entrypoint.sh Normalizes server URL inputs and adds runtime architecture compatibility checks.
Dockerfile Emits a build-time warning when building on non-x86_64/amd64 architectures.
README.md Documents x86_64-only Docker support and points ARM users to source install.
README_zh.md Same as README.md (Chinese localization).
.opencode-review/tools/gitea-pr-diff.ts Normalizes base URL and improves 404 troubleshooting for PR diff fetches.
.opencode-review/tools/gitea-pr-files.ts Normalizes base URL and improves 404 troubleshooting for PR file listing.
.opencode-review/tools/gitea-review.ts Normalizes base URL and improves 404 troubleshooting for review submission.
.opencode-review/tools/gitea-comment.ts Normalizes base URL and improves 404 troubleshooting for commenting.
.opencode-review/tools/gitea-incremental-diff.ts Normalizes base URL and improves 404 troubleshooting for incremental diff logic.

Comment on lines +23 to 24
if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!token) throw new Error("GITEA_TOKEN environment variable is required")
Comment on lines +20 to 25
const rawUrl = process.env.GITEA_SERVER_URL || process.env.GITHUB_SERVER_URL
const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN

if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!token) throw new Error("GITEA_TOKEN environment variable is required")

Comment thread entrypoint.sh
Comment on lines +79 to 83
# Normalize: remove trailing slashes and /api/v1 suffix
if [ -n "$GITEA_SERVER_URL" ]; then
export GITEA_SERVER_URL="${GITEA_SERVER_URL%/}"
export GITEA_SERVER_URL="${GITEA_SERVER_URL%/api/v1}"
return 0
Comment thread entrypoint.sh
Comment on lines 233 to 236
case "$command" in
review)
check_architecture
setup_config
Comment on lines +28 to +30
function normalizeBaseUrl(url: string): string {
return url.replace(/\/+$/, "").replace(/\/api\/v1\/?$/, "")
}
Comment on lines +33 to 37
const rawUrl = process.env.GITEA_SERVER_URL || process.env.GITHUB_SERVER_URL
const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN

if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!token) throw new Error("GITEA_TOKEN environment variable is required")
const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN

if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
Comment on lines +52 to 57
const rawUrl = process.env.GITEA_SERVER_URL || process.env.GITHUB_SERVER_URL
const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN

if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required")
if (!token) throw new Error("GITEA_TOKEN environment variable is required")

}>
}

function normalizeBaseUrl(url: string): string {
@ccsert ccsert merged commit 7451dde into main May 21, 2026
6 checks passed
@ccsert ccsert deleted the fix/issue-12-14-api-url-and-arm branch May 21, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fails on rpi4 commenting on issues does not work

2 participants