From d4d34aa029dc819f2a42725e6a0104ba24a1c9b2 Mon Sep 17 00:00:00 2001 From: claw Date: Wed, 13 May 2026 21:02:05 -0700 Subject: [PATCH] fix(action): detect VCS host type for version resolution and binary download The composite action hardcoded Gitea-specific API paths and repo references that broke when running on GitHub Enterprise Server. Changes: - Add 'action-repo' input to specify the repo hosting review-bot releases, separate from the 'repo' input (which is the target repo being reviewed) - Auto-detect action repo from github.action_repository context variable, falling back to 'rodin/review-bot' for backward compatibility - Detect VCS host type (Gitea vs GitHub) from server URL using hostname heuristic (URLs containing 'github' use /api/v3/, others use /api/v1/) - Pass computed server_url and action_repo between steps via GITHUB_OUTPUT to avoid redundant computation - Update descriptions to be host-agnostic Fixes #120 --- .gitea/actions/review/action.yml | 65 +++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/.gitea/actions/review/action.yml b/.gitea/actions/review/action.yml index 6f6fed1..cd8144c 100644 --- a/.gitea/actions/review/action.yml +++ b/.gitea/actions/review/action.yml @@ -1,17 +1,21 @@ -# This composite action is designed for Gitea Actions runners. -# Gitea Actions supports GitHub Actions syntax including $GITHUB_OUTPUT, -# actions/cache, and actions/checkout. +# This composite action supports both Gitea Actions and GitHub Actions runners. +# It detects the VCS host type (Gitea vs GitHub) from the server URL and uses +# the appropriate releases API format for version resolution and binary download. # Requirements: python3, sha256sum, curl (all present on ubuntu-* runners). name: 'AI Code Review' description: 'Run AI-powered code review on a pull request using review-bot' inputs: gitea-url: - description: 'Gitea instance URL (defaults to server_url)' + description: 'VCS instance URL (defaults to server_url). Works for both Gitea and GitHub.' required: false default: '' repo: - description: 'Repository (owner/name, defaults to current)' + description: 'Repository to review (owner/name, defaults to current)' + required: false + default: '' + action-repo: + description: 'Repository hosting review-bot releases (owner/name). Defaults to github.action_repository or rodin/review-bot.' required: false default: '' pr-number: @@ -19,7 +23,7 @@ inputs: required: false default: '' reviewer-token: - description: 'Gitea token for posting the review' + description: 'Token for posting the review' required: true reviewer-name: description: 'Display name for the reviewer' @@ -112,19 +116,50 @@ runs: id: version shell: bash run: | - GITEA_URL="${{ inputs.gitea-url || github.server_url }}" - REPO="${{ inputs.repo || 'rodin/review-bot' }}" + SERVER_URL="${{ inputs.gitea-url || github.server_url }}" + # Strip trailing slash if present + SERVER_URL="${SERVER_URL%/}" + + # Determine the repo hosting review-bot releases (not the repo being reviewed) + ACTION_REPO="${{ inputs.action-repo }}" + if [ -z "$ACTION_REPO" ]; then + # github.action_repository is the repo containing the running action + ACTION_REPO="${{ github.action_repository }}" + fi + if [ -z "$ACTION_REPO" ]; then + # Final fallback for Gitea (which may not set action_repository) + ACTION_REPO="rodin/review-bot" + fi + + # Detect VCS host type from server URL + # GitHub/GHES URLs contain "github" in the hostname + if echo "$SERVER_URL" | grep -qi "github"; then + VCS_TYPE="github" + else + VCS_TYPE="gitea" + fi + if [ "${{ inputs.version }}" = "latest" ]; then - VERSION=$(curl -sSf "${GITEA_URL}/api/v1/repos/${REPO}/releases?limit=1" \ + if [ "$VCS_TYPE" = "github" ]; then + # GitHub REST API (GHES uses /api/v3/, github.com uses /api/v3/ too) + API_URL="${SERVER_URL}/api/v3/repos/${ACTION_REPO}/releases?per_page=1" + else + # Gitea API + API_URL="${SERVER_URL}/api/v1/repos/${ACTION_REPO}/releases?limit=1" + fi + + VERSION=$(curl -sSf "$API_URL" \ | python3 -c "import sys, json; releases = json.load(sys.stdin); print(releases[0]['tag_name'] if releases else '')") if [ -z "$VERSION" ]; then - echo "Failed to determine latest version" >&2 + echo "Failed to determine latest version from ${API_URL}" >&2 exit 1 fi else VERSION="${{ inputs.version }}" fi echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "action_repo=${ACTION_REPO}" >> "$GITHUB_OUTPUT" + echo "server_url=${SERVER_URL}" >> "$GITHUB_OUTPUT" - name: Cache review-bot binary id: cache @@ -137,14 +172,16 @@ runs: if: steps.cache.outputs.cache-hit != 'true' shell: bash run: | - GITEA_URL="${{ inputs.gitea-url || github.server_url }}" - REPO="${{ inputs.repo || 'rodin/review-bot' }}" + SERVER_URL="${{ steps.version.outputs.server_url }}" + ACTION_REPO="${{ steps.version.outputs.action_repo }}" VERSION="${{ steps.version.outputs.version }}" BINARY="review-bot-linux-amd64" - curl -sSfL "${GITEA_URL}/${REPO}/releases/download/${VERSION}/${BINARY}" \ + # Download URL format is the same on both Gitea and GitHub: + # {server}/{owner}/{repo}/releases/download/{tag}/{asset} + curl -sSfL "${SERVER_URL}/${ACTION_REPO}/releases/download/${VERSION}/${BINARY}" \ -o "${{ runner.temp }}/review-bot" - curl -sSfL "${GITEA_URL}/${REPO}/releases/download/${VERSION}/checksums.txt" \ + curl -sSfL "${SERVER_URL}/${ACTION_REPO}/releases/download/${VERSION}/checksums.txt" \ -o "${{ runner.temp }}/checksums.txt" # Verify SHA-256 checksum