Actualiser gitea_push/scripts/smart_commit.sh

This commit is contained in:
2026-01-19 06:44:03 +01:00
parent 504b5bd53a
commit bf6834fe46

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env bash
SCOPE="plugin"
elif echo "$CHANGED_FILES" | grep -q "skill"; then
SCOPE="skill"
elif echo "$CHANGED_FILES" | grep -q "agent"; then
SCOPE="agent"
else
FIRST_FILE=$(echo "$CHANGED_FILES" | head -n 1)
if [[ "$FIRST_FILE" == */* ]]; then
SCOPE="${FIRST_FILE%%/*}"
fi
fi
# Determine description
DESC=""
if [[ "$TYPE" == "docs" ]]; then
DESC="update documentation"
elif [[ "$TYPE" == "test" ]]; then
DESC="update tests"
elif [[ "$TYPE" == "chore" ]]; then
DESC="update dependencies"
else
FILE_COUNT=$(echo "$CHANGED_FILES" | wc -l | tr -d ' ')
DESC="update ${FILE_COUNT} file(s)"
fi
if [[ -n "$SCOPE" ]]; then
COMMIT_MSG="${TYPE}(${SCOPE}): ${DESC}"
else
COMMIT_MSG="${TYPE}: ${DESC}"
fi
fi
info "Commit message: $COMMIT_MSG"
# -----------------------------
# Commit
# -----------------------------
info "Creating commit..."
git commit -m "$COMMIT_MSG" -m "Generated with Claude Code" -m "Co-Authored-By: Claude <noreply@anthropic.com>"
# -----------------------------
# Push
# -----------------------------
info "Pushing to remote '$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 complete"
echo "$DIFF_STAT"
# -----------------------------
# Gitea PR link (best-effort)
# -----------------------------
# For Gitea, creating a PR is usually:
# 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
HOST="${HP%%|*}"
PATH_REPO="${HP#*|}"
PATH_REPO="${PATH_REPO%.git}"
# If configured host matches (or no configured host)
if [[ -z "${GITEA_HOST:-}" || "$HOST" == "$GITEA_HOST" ]]; then
warn "Create PR: https://${HOST}/${PATH_REPO}/compare/${BRANCH}?expand=1"
fi
fi