diff --git a/git-hangman-lab/SKILL.md b/git-hangman-lab/SKILL.md index 6bbdf55..0868da9 100644 --- a/git-hangman-lab/SKILL.md +++ b/git-hangman-lab/SKILL.md @@ -33,6 +33,16 @@ Generate an access token for the current user. {baseDir}/scripts/git-ctrl generate-access-token ``` +### Create Repository + +Create a new git repository on git.hangman-lab.top. + +```bash +{baseDir}/scripts/git-ctrl create-repo +``` + +> **Note**: The repository will be created at `${AGENT_WORKSPACE}/${repo-name}` (default: `/root/.openclaw/workspace/workspace-mentor`) + ### Link Keycloak Account Link Keycloak account with Gitea (for OAuth binding). diff --git a/git-hangman-lab/scripts/create-repo b/git-hangman-lab/scripts/create-repo new file mode 100755 index 0000000..a0f9bbd --- /dev/null +++ b/git-hangman-lab/scripts/create-repo @@ -0,0 +1,59 @@ +#!/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 " + 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}" diff --git a/git-hangman-lab/scripts/git-ctrl b/git-hangman-lab/scripts/git-ctrl index 44082e5..21f3517 100755 --- a/git-hangman-lab/scripts/git-ctrl +++ b/git-hangman-lab/scripts/git-ctrl @@ -10,12 +10,13 @@ if [[ $# -eq 0 ]]; then echo "Commands:" echo " check-git-cred Verify git credentials" echo " create-git-account Create a new git account" - echo " generate-access-token Generate access token for current user" - echo " link-keycloak Link Keycloak account with Gitea" - echo " repo-add-collaborators Add collaborator to repository" - echo " repo-config Configure repository" - echo " external-login-ctrl Enable/disable local login" - echo " reset-password Reset user password" + echo " create-repo Create a new repository" + echo " generate-access-token Generate access token for current user" + echo " link-keycloak Link Keycloak account with Gitea" + echo " repo-add-collaborators Add collaborator to repository" + echo " repo-config Configure repository" + echo " external-login-ctrl Enable/disable local login" + echo " reset-password Reset user password" exit 1 fi @@ -31,6 +32,9 @@ case "$subcommand" in create-git-account) "$SCRIPT_DIR/create-git-account" "$@" ;; + create-repo) + "$SCRIPT_DIR/create-repo" "$@" + ;; generate-access-token) "$SCRIPT_DIR/generate-access-token" "$@" ;;