From b17a6fef7c24d4c1157a8a684a14b813a96dacd0 Mon Sep 17 00:00:00 2001 From: Arlind Date: Sun, 23 Nov 2025 15:05:07 +0100 Subject: [PATCH] Update .gitea/actions/test-links/action.yml --- .gitea/actions/test-links/action.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitea/actions/test-links/action.yml b/.gitea/actions/test-links/action.yml index 9a9ed7c..d905c7b 100644 --- a/.gitea/actions/test-links/action.yml +++ b/.gitea/actions/test-links/action.yml @@ -99,16 +99,32 @@ runs: echo " $status $decoded_link" >> /tmp/download_$$.txt fi else - # Local file - remove leading slash if present - if [[ "$decoded_link" =~ ^/ ]]; then - file_path="${decoded_link#/}" + # Local file - check via Gitea API + if [[ "$link" =~ ^/ ]]; then + # Absolute path from repo root + api_path="${link#/}" else + # Relative path from markdown file md_dir=$(dirname "$md_file") - file_path="$md_dir/$decoded_link" + if [[ "$md_dir" == "." ]]; then + api_path="$link" + else + api_path="${md_dir#./}/$link" + fi fi - # Check if file exists - if ! [ -f "$file_path" ]; then + # Get repository info from git remote + if [ -z "$REPO_OWNER" ]; then + REPO_OWNER=$(git config --get remote.origin.url | sed -n 's|.*[:/]\([^/]*\)/[^/]*\.git|\1|p' || echo "") + REPO_NAME=$(git config --get remote.origin.url | sed -n 's|.*[:/][^/]*/\([^/]*\)\.git|\1|p' || echo "") + GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main") + fi + + # Check file via Gitea API + api_url="http://gitea:3000/api/v1/repos/$REPO_OWNER/$REPO_NAME/contents/$api_path?ref=$GIT_BRANCH" + http_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$api_url" 2>/dev/null || echo "000") + + if ! [[ "$http_code" =~ ^[23][0-9][0-9]$ ]]; then status="✖ (not found)" file_has_errors=1 has_errors=1