Files
ClawSkills/git-hangman-lab/scripts/create-repo
lyn ca9d3b4fe5 feat(git-hangman-lab): add create-repo command
- Add create-repo script for creating new repositories on git.hangman-lab.top
- Integrate create-repo into git-ctrl dispatcher
- Update SKILL.md with new command documentation
2026-04-01 00:38:47 +00:00

60 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Default workspace (can be overridden by AGENT_WORKSPACE env var)
AGENT_WORKSPACE="${AGENT_WORKSPACE:-/root/.openclaw/workspace/workspace-mentor}"
usage() {
echo "Usage: $0 <repo-name>"
echo ""
echo "Create a new git repository on git.hangman-lab.top"
echo ""
echo "Arguments:"
echo " repo-name Name of the repository to create"
exit 2
}
if [[ $# -eq 0 ]]; then
usage
fi
REPO_NAME="$1"
# Validate repo name (alphanumeric, hyphens, underscores only)
if ! [[ "$REPO_NAME" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo "Error: Invalid repository name '$REPO_NAME'"
echo "Only alphanumeric characters, hyphens, and underscores are allowed."
exit 1
fi
REPO_DIR="${AGENT_WORKSPACE}/${REPO_NAME}"
# Step 1: Create directory
echo "Creating directory: ${REPO_DIR}"
mkdir -p "${REPO_DIR}"
# Step 2: cd to directory
cd "${REPO_DIR}"
# Step 3: git init
echo "Initializing git repository..."
git init
# Step 4: git remote add origin
echo "Adding remote origin..."
USERNAME="$(secret-mgr get-username --key git)"
REMOTE_URL="https://git.hangman-lab.top/${USERNAME}/${REPO_NAME}.git"
git remote add origin "${REMOTE_URL}"
echo " Remote: ${REMOTE_URL}"
# Step 5: Run repo-config
echo "Configuring repository..."
"$SCRIPT_DIR/repo-config" --repo-path "${REPO_DIR}"
echo ""
echo "Done! Repository created at: ${REPO_DIR}"
echo "Remote: ${REMOTE_URL}"