maj
This commit is contained in:
@@ -1,37 +1,38 @@
|
|||||||
---
|
---
|
||||||
name: git-pushing
|
name: gitea_push
|
||||||
description: Automates staging, committing, and pushing changes to Git when the user asks to commit and 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”
|
Ce skill apprend à Claude à automatiser le workflow Git suivant :
|
||||||
- “push to remote”
|
- ajout des fichiers modifiés au staging,
|
||||||
- “pousse les changements”
|
- création d’un commit,
|
||||||
- “git push”
|
- envoi des changements vers le dépôt distant.
|
||||||
- similar phrases indicating a Git commit + push flow
|
|
||||||
|
|
||||||
## 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.
|
### Exemples d’exécution
|
||||||
2. Commit with either:
|
|
||||||
- a generated message if none specified, or
|
|
||||||
- a user-provided commit message.
|
|
||||||
3. Push commits to the configured remote.
|
|
||||||
|
|
||||||
### Run Script Examples
|
Exécution standard (depuis la racine du repo, ou depuis le dossier du skill) :
|
||||||
|
```bash
|
||||||
- Default invocation:
|
bash gitea_push/scripts/smart_commit.sh
|
||||||
|
```
|
||||||
```bash
|
|
||||||
bash skills/git-pushing/scripts/smart_commit.sh
|
|
||||||
|
|||||||
@@ -1,92 +1,84 @@
|
|||||||
#!/usr/bin/env bash
|
---
|
||||||
fi
|
info "Commit créé : ${COMMIT_HASH}"
|
||||||
|
|
||||||
|
|
||||||
# Description (FR)
|
# Push helpers
|
||||||
if [[ "$TYPE" == "docs" ]]; then
|
get_remote_url() {
|
||||||
DESC="mise à jour de la documentation"
|
git remote get-url "${GIT_REMOTE}" 2>/dev/null || true
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if HP=$(extract_host_and_path "$REMOTE_URL"); then
|
# Build an authenticated URL for one-shot push (does not change remote config)
|
||||||
HOST="${HP%%|*}"
|
# Works for https remotes.
|
||||||
PATH_REPO="${HP#*|}"
|
make_auth_url_from_remote() {
|
||||||
PATH_REPO="${PATH_REPO%.git}"
|
local remote_url="$1"
|
||||||
|
|
||||||
|
|
||||||
if [[ -z "${GITEA_HOST:-}" || "$HOST" == "$GITEA_HOST" ]]; then
|
if [ -z "${GITEA_HOST:-}" ] || [ -z "${GITEA_USER:-}" ] || [ -z "${GITEA_TOKEN:-}" ]; then
|
||||||
warn "Créer une PR : https://${HOST}/${PATH_REPO}/compare/${BRANCH}?expand=1"
|
echo ""
|
||||||
|
return
|
||||||
fi
|
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
|
||||||
|
|||||||
15
gitea_push/secrets/gitea.env
Normal file
15
gitea_push/secrets/gitea.env
Normal file
@@ -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"
|
||||||
Reference in New Issue
Block a user