This commit is contained in:
2026-01-19 21:30:14 +01:00
parent 756f0833b5
commit 6940cb3f32
3 changed files with 117 additions and 109 deletions

View File

@@ -1,92 +1,84 @@
#!/usr/bin/env bash
fi
---
info "Commit créé : ${COMMIT_HASH}"
# Description (FR)
if [[ "$TYPE" == "docs" ]]; then
DESC="mise à jour de la documentation"
elif [[ "$TYPE" == "test" ]]; then
DESC="mise à jour des tests"
elif [[ "$TYPE" == "chore" ]]; then
DESC="mise à jour des dépendances"
elif [[ "$TYPE" == "fix" ]]; then
DESC="correction"
elif [[ "$TYPE" == "refactor" ]]; then
DESC="refactorisation"
else
FILE_COUNT=$(echo "$CHANGED_FILES" | wc -l | tr -d ' ')
DESC="mise à jour de ${FILE_COUNT} fichier(s)"
fi
if [[ -n "$SCOPE" ]]; then
COMMIT_MSG="${TYPE}(${SCOPE}): ${DESC}"
else
COMMIT_MSG="${TYPE}: ${DESC}"
fi
fi
info "Message de commit : $COMMIT_MSG"
# -----------------------------
# Commit
# -----------------------------
info "Création du commit…"
git commit -m "$COMMIT_MSG" -m "Généré avec Claude Code" -m "Co-Authored-By: Claude <noreply@anthropic.com>"
# -----------------------------
# Push
# -----------------------------
info "Push vers '$REMOTE_NAME'…"
if git ls-remote --exit-code --heads "$REMOTE_NAME" "$BRANCH" >/dev/null 2>&1; then
git push "$REMOTE_NAME"
else
git push -u "$REMOTE_NAME" "$BRANCH"
fi
info "Push terminé"
echo "$DIFF_STAT"
# -----------------------------
# Lien PR Gitea (best-effort)
# -----------------------------
# Format courant : https://host/owner/repo/compare/<branch>?expand=1
REMOTE_URL=$(git remote get-url "$REMOTE_NAME" 2>/dev/null || true)
extract_host_and_path() {
local url="$1"
if [[ "$url" =~ ^https?://([^/]+)/(.+)$ ]]; then
echo "${BASH_REMATCH[1]}|${BASH_REMATCH[2]}"
return 0
elif [[ "$url" =~ ^git@([^:]+):(.+)$ ]]; then
echo "${BASH_REMATCH[1]}|${BASH_REMATCH[2]}"
return 0
fi
return 1
# Push helpers
get_remote_url() {
git remote get-url "${GIT_REMOTE}" 2>/dev/null || true
}
if HP=$(extract_host_and_path "$REMOTE_URL"); then
HOST="${HP%%|*}"
PATH_REPO="${HP#*|}"
PATH_REPO="${PATH_REPO%.git}"
# Build an authenticated URL for one-shot push (does not change remote config)
# Works for https remotes.
make_auth_url_from_remote() {
local remote_url="$1"
if [[ -z "${GITEA_HOST:-}" || "$HOST" == "$GITEA_HOST" ]]; then
warn "Créer une PR : https://${HOST}/${PATH_REPO}/compare/${BRANCH}?expand=1"
if [ -z "${GITEA_HOST:-}" ] || [ -z "${GITEA_USER:-}" ] || [ -z "${GITEA_TOKEN:-}" ]; then
echo ""
return
fi
fi
# Only for http(s)
if ! echo "$remote_url" | grep -qE '^https?://'; then
echo ""
return
fi
# Extract path after host
# Accepts:
# https://gitea.host/user/repo.git
# https://gitea.host/user/repo
local path
path=$(echo "$remote_url" | sed -E 's#^https?://[^/]+/##')
# If remote points to a different host, skip
if ! echo "$remote_url" | grep -q "${GITEA_HOST}"; then
echo ""
return
fi
# Auth URL
echo "https://${GITEA_USER}:${GITEA_TOKEN}@${GITEA_HOST}/${path}"
}
# Push
info "Push vers ${GIT_REMOTE}/${CURRENT_BRANCH}"
set +e
if git push "${GIT_REMOTE}" "${CURRENT_BRANCH}"; then
set -e
info "Push OK"
echo "$DIFF_STAT"
exit 0
fi
set -e
warn "Push standard échoué. Tentative de fallback via token (si configuré)."
REMOTE_URL="$(get_remote_url)"
AUTH_URL="$(make_auth_url_from_remote "$REMOTE_URL")"
if [ -n "$AUTH_URL" ]; then
set +e
if git push "$AUTH_URL" "${CURRENT_BRANCH}"; then
set -e
info "Push OK via URL authentifiée (remote inchangé)"
echo "$DIFF_STAT"
exit 0
fi
set -e
fi
error "Push échoué. Vérifier : droits Gitea, token, remote ${GIT_REMOTE}, ou credentials git."
exit 1