diff --git a/gitea_push/SKILL.md b/gitea_push/SKILL.md index 7f19e01..93fa6d9 100644 --- a/gitea_push/SKILL.md +++ b/gitea_push/SKILL.md @@ -1,37 +1,38 @@ --- -name: git-pushing -description: Automates staging, committing, and pushing changes to Git when the user asks to commit and push. +name: gitea_push +description: Stage, commit et push les changements Git vers un dépôt Gitea avec un message de commit de type Conventional Commits. À utiliser quand l’utilisateur demande de « commit », « push », « commit et push », « envoyer sur gitea », « pousser sur le remote », etc. --- -# Git Pushing +# Workflow Gitea Push -## Intent +Objectif : **stager**, **commiter** (message Conventional Commits) et **pusher** sur la branche courante. -This skill teaches Claude how to automate the workflow of staging changes, creating a commit, and pushing to the remote repository. +## Langue -## When to Use +- Claude **doit répondre en français** lors de l’utilisation de ce skill. +- Les **messages de commit doivent être rédigés en français**. -Activate this skill when the user request mentions: +## Intention -- “commit and push” -- “push to remote” -- “pousse les changements” -- “git push” -- similar phrases indicating a Git commit + push flow +Ce skill apprend à Claude à automatiser le workflow Git suivant : +- ajout des fichiers modifiés au staging, +- création d’un commit, +- envoi des changements vers le dépôt distant. -## Instructions +## Quand l’utiliser +Déclenchement automatique quand l’utilisateur : +- demande explicitement de pousser (`push`, `commit et push`, `envoie ça sur gitea`) +- veut sauvegarder son travail sur le remote +- a terminé une étape et souhaite publier les changements -Claude should execute the provided script to: +## Règles +- **Toujours** utiliser le script ci-dessous. +- **Ne pas** exécuter de commandes git manuelles hors script. +- Le script doit lire la config depuis `secrets/gitea.env`. -1. Stage all changes. -2. Commit with either: - - a generated message if none specified, or - - a user-provided commit message. -3. Push commits to the configured remote. +### Exemples d’exécution -### Run Script Examples - -- Default invocation: - - ```bash - bash skills/git-pushing/scripts/smart_commit.sh +Exécution standard (depuis la racine du repo, ou depuis le dossier du skill) : +```bash +bash gitea_push/scripts/smart_commit.sh +``` diff --git a/gitea_push/scripts/smart_commit.sh b/gitea_push/scripts/smart_commit.sh index 8b2701f..cfc04f6 100644 --- a/gitea_push/scripts/smart_commit.sh +++ b/gitea_push/scripts/smart_commit.sh @@ -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 " - - -# ----------------------------- -# 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/?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 \ No newline at end of file + + +# 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 diff --git a/gitea_push/secrets/gitea.env b/gitea_push/secrets/gitea.env new file mode 100644 index 0000000..72e9687 --- /dev/null +++ b/gitea_push/secrets/gitea.env @@ -0,0 +1,15 @@ + +# Hôte Gitea (sans protocole) +GITEA_HOST="gitea.maison43.duckdns.org" + + +# Utilisateur Gitea +GITEA_USER="gilles" + + +# Token d’accès (PAT) — garder ce fichier hors git +GITEA_TOKEN="652264c84a7f8bcb7bf89bf744339bd35f172b1a" + + +# Remote git à utiliser (optionnel) +GIT_REMOTE="origin"