fix(#812): preserve configured gitea API base URL
This commit is contained in:
@@ -81,7 +81,14 @@ get_repo_slug() {
|
||||
gitea_url_matches_host() {
|
||||
local url="${1:-}" host="${2:-}"
|
||||
[[ -n "$url" && -n "$host" ]] || return 1
|
||||
[[ "${url%/}" == "https://$host" || "${url%/}" == "http://$host" || "${url%/}" == *"//$host" ]]
|
||||
python3 - "$url" "$host" <<'PY'
|
||||
import sys
|
||||
from urllib.parse import urlparse
|
||||
|
||||
url, host = sys.argv[1:]
|
||||
parsed = urlparse(url)
|
||||
raise SystemExit(0 if parsed.scheme in {"http", "https"} and parsed.hostname == host else 1)
|
||||
PY
|
||||
}
|
||||
|
||||
get_gitea_service_for_host() {
|
||||
@@ -377,6 +384,51 @@ get_remote_host() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Resolve the configured Gitea base URL for a host from the same credential
|
||||
# source used by get_gitea_token. The scheme and any deployment path prefix are
|
||||
# provider configuration and must not be reconstructed from the git remote.
|
||||
get_gitea_url_for_host() {
|
||||
local host="$1" script_dir cred_loader url
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cred_loader="$script_dir/../_lib/credentials.sh"
|
||||
|
||||
if [[ -f "$cred_loader" ]]; then
|
||||
url=$(
|
||||
# shellcheck source=/dev/null
|
||||
source "$cred_loader"
|
||||
unset GITEA_TOKEN GITEA_URL
|
||||
case "$host" in
|
||||
git.mosaicstack.dev) load_credentials gitea-mosaicstack 2>/dev/null ;;
|
||||
git.uscllc.com) load_credentials gitea-usc 2>/dev/null ;;
|
||||
*)
|
||||
for svc in gitea-mosaicstack gitea-usc; do
|
||||
unset GITEA_TOKEN GITEA_URL
|
||||
load_credentials "$svc" 2>/dev/null || continue
|
||||
if gitea_url_matches_host "${GITEA_URL:-}" "$host"; then
|
||||
break
|
||||
fi
|
||||
unset GITEA_TOKEN GITEA_URL
|
||||
done
|
||||
;;
|
||||
esac
|
||||
if gitea_url_matches_host "${GITEA_URL:-}" "$host"; then
|
||||
printf '%s' "${GITEA_URL%/}"
|
||||
fi
|
||||
)
|
||||
if [[ -n "$url" ]]; then
|
||||
printf '%s\n' "$url"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if gitea_url_matches_host "${GITEA_URL:-}" "$host"; then
|
||||
printf '%s\n' "${GITEA_URL%/}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Resolve a Gitea API token for the given host.
|
||||
# Priority: Mosaic credential loader → GITEA_TOKEN env → ~/.git-credentials
|
||||
get_gitea_token() {
|
||||
@@ -403,7 +455,7 @@ get_gitea_token() {
|
||||
for svc in gitea-mosaicstack gitea-usc; do
|
||||
unset GITEA_TOKEN GITEA_URL
|
||||
load_credentials "$svc" 2>/dev/null || continue
|
||||
if [[ "${GITEA_URL:-}" == "https://$host" || "${GITEA_URL:-}" == "http://$host" || "${GITEA_URL:-}" == *"//$host" ]]; then
|
||||
if gitea_url_matches_host "${GITEA_URL:-}" "$host"; then
|
||||
matched=true
|
||||
break
|
||||
fi
|
||||
@@ -423,7 +475,7 @@ get_gitea_token() {
|
||||
|
||||
# 2. GITEA_TOKEN env var (only when GITEA_URL, if present, matches the remote host)
|
||||
if [[ -n "${GITEA_TOKEN:-}" ]]; then
|
||||
if [[ -z "${GITEA_URL:-}" || "${GITEA_URL:-}" == "https://$host" || "${GITEA_URL:-}" == "http://$host" || "${GITEA_URL:-}" == *"//$host" ]]; then
|
||||
if [[ -z "${GITEA_URL:-}" ]] || gitea_url_matches_host "$GITEA_URL" "$host"; then
|
||||
echo "$GITEA_TOKEN"
|
||||
return 0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user