| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #!/bin/bash
- # Script to handle issue automation with Claude Code
- # This script is called when an issue is opened or commented on
- # Parse arguments
- OWNER="$1"
- REPO="$2"
- PUSHER="$3"
- ISSUE_NUMBER="$4"
- ISSUE_TITLE="$5"
- ISSUE_BODY="$6"
- ISSUE_ACTION="$7"
- COMMENT_BODY="$8"
- ASSIGNEE="$9"
- # Exit if pusher is claude (avoid loops)
- if [ "$PUSHER" = "claude" ]; then
- echo "Pusher is claude, skipping automation to avoid loops"
- exit 0
- fi
- # Exit if issue is not assigned to claude
- if [ "$ASSIGNEE" != "claude" ]; then
- echo "Issue not assigned to claude (assignee: $ASSIGNEE), skipping"
- exit 0
- fi
- # Determine repo path
- REPO_PATH="$HOME/$OWNER/$REPO"
- # Check if repo exists, if not clone it
- if [ ! -d "$REPO_PATH" ]; then
- echo "Repository not found at $REPO_PATH, cloning..."
- mkdir -p "$HOME/$OWNER"
- GIT_URL="ssh://git@207.154.220.231:10022/$OWNER/$REPO.git"
- git clone "$GIT_URL" "$REPO_PATH"
- if [ $? -ne 0 ]; then
- echo "Failed to clone repository"
- exit 1
- fi
- echo "Repository cloned successfully"
- else
- echo "Repository found at $REPO_PATH"
- # Pull latest changes
- cd "$REPO_PATH" || exit 1
- echo "Pulling latest changes..."
- git pull
- fi
- # Change to repo directory
- cd "$REPO_PATH" || exit 1
- echo "Working directory: $(pwd)"
- # Build the prompt for Claude
- if [ -n "$COMMENT_BODY" ]; then
- # Issue comment event
- PROMPT="A comment was added to issue #$ISSUE_NUMBER in $OWNER/$REPO by $PUSHER.
- Issue Title: $ISSUE_TITLE
- Original Issue:
- $ISSUE_BODY
- New Comment:
- $COMMENT_BODY
- Please review the comment and respond appropriately. This issue is assigned to you."
- else
- # Issue opened/reopened event
- PROMPT="Issue #$ISSUE_NUMBER was $ISSUE_ACTION in $OWNER/$REPO by $PUSHER.
- Issue Title: $ISSUE_TITLE
- Issue Description:
- $ISSUE_BODY
- This issue is assigned to you. Please review and handle it accordingly."
- fi
- echo "Calling Claude Code with the issue information..."
- echo "---"
- # Call claude with the prompt
- claude -p "$PROMPT"
- echo "---"
- echo "Claude Code execution completed"
|