diff --git a/git-hangman-lab/SKILL.md b/git-hangman-lab/SKILL.md index 85511ec..bf0e2a9 100644 --- a/git-hangman-lab/SKILL.md +++ b/git-hangman-lab/SKILL.md @@ -54,7 +54,6 @@ Manage pull requests on git.hangman-lab.top. {baseDir}/scripts/git-ctrl pr merge [commit-id] [title] [message] {baseDir}/scripts/git-ctrl pr show ``` -``` > **Note**: The access token will be automatically generated if not found. diff --git a/git-hangman-lab/scripts/create-pr b/git-hangman-lab/scripts/create-pr deleted file mode 100755 index 6841682..0000000 --- a/git-hangman-lab/scripts/create-pr +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get the directory where this script is located -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" - -usage() { - echo "Usage: $0 [pr-title] [pr-body]" - echo "" - echo "Create a pull request on git.hangman-lab.top" - echo "" - echo "Arguments:" - echo " repo-local-path Local path to the git repository" - echo " head-branch Branch containing the changes" - echo " base-branch Branch to merge into (e.g., main)" - echo " pr-title Title of the pull request (optional, default: 'untitled pull request')" - echo " pr-body Body/description of the pull request (optional, default: '')" - exit 2 -} - -if [[ $# -lt 3 ]]; then - usage -fi - -REPO_LOCAL_PATH="$1" -HEAD_BRANCH="$2" -BASE_BRANCH="$3" -PR_TITLE="${4:-untitled pull request}" -PR_BODY="${5:-}" - -# Validate repo path -if [[ ! -d "$REPO_LOCAL_PATH/.git" ]]; then - echo "Error: Not a git repository: $REPO_LOCAL_PATH" - exit 1 -fi - -# Check if git-access-token exists, if not generate it -if ! secret-mgr list 2>/dev/null | grep -q "git-access-token"; then - echo "Access token not found, generating..." - "$SCRIPT_DIR/generate-access-token" -fi - -# Get the access token (extract actual token from "Access token was successfully created: ") -GIT_TOKEN="$(secret-mgr get-secret --key git-access-token | awk '{print $NF}')" - -if [[ -z "$GIT_TOKEN" ]]; then - echo "Error: Failed to get git-access-token" - exit 1 -fi - -# Get remote URL from .git -REMOTE_URL="$(git -C "$REPO_LOCAL_PATH" remote get-url origin)" - -# Match pattern: https://git.hangman-lab.top/${owner}/${repo-name}.git -if [[ "$REMOTE_URL" =~ https://git\.hangman-lab\.top/([^/]+)/([^/]+)\.git ]]; then - OWNER="${BASH_REMATCH[1]}" - REPO_NAME="${BASH_REMATCH[2]}" -else - echo "Error: Invalid remote URL format: $REMOTE_URL" - echo "Expected: https://git.hangman-lab.top/\${owner}/\${repo-name}.git" - exit 1 -fi - -echo "Creating PR: $OWNER/$REPO_NAME ($HEAD_BRANCH -> $BASE_BRANCH)" - -# Create PR via API -RESPONSE=$(curl -s -X POST "https://git.hangman-lab.top/api/v1/repos/${OWNER}/${REPO_NAME}/pulls" \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -H "Authorization: token ${GIT_TOKEN}" \ - -d "$(jq -n \ - --arg head "$HEAD_BRANCH" \ - --arg base "$BASE_BRANCH" \ - --arg title "$PR_TITLE" \ - --arg body "$PR_BODY" \ - '{head: $head, base: $base, title: $title, body: $body}')") - -# Check if response contains an error -if echo "$RESPONSE" | jq -e '.message' >/dev/null 2>&1; then - ERROR_MSG=$(echo "$RESPONSE" | jq -r '.message') - echo "Error: $ERROR_MSG" - exit 1 -fi - -# Extract PR URL from response -PR_URL=$(echo "$RESPONSE" | jq -r '.html_url // empty') - -if [[ -n "$PR_URL" ]]; then - echo "Pull request created successfully!" - echo "URL: $PR_URL" -else - echo "Error: Failed to create pull request" - echo "Response: $RESPONSE" - exit 1 -fi diff --git a/git-hangman-lab/scripts/git-ctrl b/git-hangman-lab/scripts/git-ctrl index 1cf1cc4..11a13e3 100755 --- a/git-hangman-lab/scripts/git-ctrl +++ b/git-hangman-lab/scripts/git-ctrl @@ -37,7 +37,7 @@ case "$subcommand" in "$SCRIPT_DIR/create-repo" "$@" ;; pr) - "$SCRIPT_DIR/pr" "$@" + "$SCRIPT_DIR/pr" "$@" ;; generate-access-token) "$SCRIPT_DIR/generate-access-token" "$@"