Merge pull request 'feature/add-create-repo-script' (#2) from feature/add-create-repo-script into main
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
@@ -33,6 +33,16 @@ Generate an access token for the current user.
|
|||||||
{baseDir}/scripts/git-ctrl generate-access-token
|
{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 <repo-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note**: The repository will be created at `${AGENT_WORKSPACE}/${repo-name}` (default: `/root/.openclaw/workspace/workspace-mentor`)
|
||||||
|
|
||||||
### Link Keycloak Account
|
### Link Keycloak Account
|
||||||
|
|
||||||
Link Keycloak account with Gitea (for OAuth binding).
|
Link Keycloak account with Gitea (for OAuth binding).
|
||||||
|
|||||||
61
git-hangman-lab/scripts/create-repo
Executable file
61
git-hangman-lab/scripts/create-repo
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Get the directory where this script is located
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
|
if [[ -z "${AGENT_WORKSPACE:-}" ]]; then
|
||||||
|
echo "Error: script must be executed by pcexec"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
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}"
|
||||||
@@ -10,12 +10,13 @@ if [[ $# -eq 0 ]]; then
|
|||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " check-git-cred Verify git credentials"
|
echo " check-git-cred Verify git credentials"
|
||||||
echo " create-git-account Create a new git account"
|
echo " create-git-account Create a new git account"
|
||||||
echo " generate-access-token Generate access token for current user"
|
echo " create-repo Create a new repository"
|
||||||
echo " link-keycloak Link Keycloak account with Gitea"
|
echo " generate-access-token Generate access token for current user"
|
||||||
echo " repo-add-collaborators Add collaborator to repository"
|
echo " link-keycloak Link Keycloak account with Gitea"
|
||||||
echo " repo-config Configure repository"
|
echo " repo-add-collaborators Add collaborator to repository"
|
||||||
echo " external-login-ctrl Enable/disable local login"
|
echo " repo-config Configure repository"
|
||||||
echo " reset-password Reset user password"
|
echo " external-login-ctrl Enable/disable local login"
|
||||||
|
echo " reset-password Reset user password"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -31,6 +32,9 @@ case "$subcommand" in
|
|||||||
create-git-account)
|
create-git-account)
|
||||||
"$SCRIPT_DIR/create-git-account" "$@"
|
"$SCRIPT_DIR/create-git-account" "$@"
|
||||||
;;
|
;;
|
||||||
|
create-repo)
|
||||||
|
"$SCRIPT_DIR/create-repo" "$@"
|
||||||
|
;;
|
||||||
generate-access-token)
|
generate-access-token)
|
||||||
"$SCRIPT_DIR/generate-access-token" "$@"
|
"$SCRIPT_DIR/generate-access-token" "$@"
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user