Publish gitea-publish via gitea-publish skill

This commit is contained in:
figmar
2026-08-06 09:14:17 +08:00
parent 97575458f4
commit f3fa427702
2 changed files with 20 additions and 5 deletions
+14 -4
View File
@@ -9,6 +9,7 @@ PATH_=""
URL="${GITEA_URL:-}"
USER="${GITEA_USER:-}"
TOKEN="${GITEA_TOKEN:-}"
DISPLAY_URL=""
PRIVATE="false"
BRANCH=""
@@ -17,6 +18,7 @@ while [[ $# -gt 0 ]]; do
--repo) REPO="$2"; shift 2;;
--path) PATH_="$2"; shift 2;;
--url) URL="$2"; shift 2;;
--display-url) DISPLAY_URL="$2"; shift 2;;
--user) USER="$2"; shift 2;;
--token) TOKEN="$2"; shift 2;;
--private) PRIVATE="true"; shift;;
@@ -36,6 +38,13 @@ done
# 规范化:去掉结尾斜杠
URL="${URL%/}"
# 对外透出的 Web 地址:默认使用公开域名 gitea.apescale.com。
# 即使 git 推送 / API 调用走的是内网地址或 IP,最终展示给用户的链接
# 也始终落在公开域名下,避免把内网主机名 / IP 直接暴露出来。
DISPLAY_URL="${DISPLAY_URL:-${GITEA_DISPLAY_URL:-https://gitea.apescale.com}}"
DISPLAY_URL="${DISPLAY_URL%/}"
WEB_URL="$DISPLAY_URL/$USER/$REPO"
# 对凭据做 URL 百分号编码(口令可能含 # $ @ 等特殊字符)
urlencode() { python3 -c 'import sys,urllib.parse;print(urllib.parse.quote(sys.argv[1],safe=""))' "$1"; }
U_ENC="$(urlencode "$USER")"
@@ -52,9 +61,10 @@ fi
[[ -z "$BRANCH" ]] && BRANCH="main"
API="$URL/api/v1"
HOST="${URL#*//}"
REMOTE_CLEAN="https://$HOST/$USER/$REPO.git"
REMOTE_AUTH="https://$AUTH_ENC@$HOST/$USER/$REPO.git"
PROTO="${URL%%://*}" # 从 URL 提取协议 (http 或 https)
HOST="${URL#*//}" # 提取主机+端口
REMOTE_CLEAN="$PROTO://$HOST/$USER/$REPO.git"
REMOTE_AUTH="$PROTO://$AUTH_ENC@$HOST/$USER/$REPO.git"
echo "==> 检查仓库 $USER/$REPO 是否存在 ..."
HTTP="$(curl -sS -o /dev/null -w '%{http_code}' -u "$AUTH_RAW" "$API/repos/$USER/$REPO")"
@@ -106,4 +116,4 @@ fi
# 用一次性带口令 URL 推送,不设置含口令的 upstream
git push "$REMOTE_AUTH" "$BRANCH"
git branch --set-upstream-to="origin/$BRANCH" 2>/dev/null || true
echo "==> 完成。仓库地址: $URL/$USER/$REPO"
echo "==> 完成。仓库地址: $WEB_URL"