handle-issue.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # Script to handle issue automation with Claude Code
  3. # This script is called when an issue is opened or commented on
  4. # Add claude binary to PATH
  5. export PATH="$HOME/.local/bin:$PATH"
  6. # Parse arguments
  7. OWNER="$1"
  8. REPO="$2"
  9. PUSHER="$3"
  10. ISSUE_NUMBER="$4"
  11. ISSUE_TITLE="$5"
  12. ISSUE_BODY="$6"
  13. ISSUE_ACTION="$7"
  14. COMMENT_BODY="$8"
  15. ASSIGNEE="$9"
  16. # Exit if pusher is claude (avoid loops)
  17. if [ "$PUSHER" = "claude" ]; then
  18. echo "Pusher is claude, skipping automation to avoid loops"
  19. exit 0
  20. fi
  21. # Exit if issue is not assigned to claude
  22. if [ "$ASSIGNEE" != "claude" ]; then
  23. echo "Issue not assigned to claude (assignee: $ASSIGNEE), skipping"
  24. exit 0
  25. fi
  26. # Determine repo path
  27. REPO_PATH="$HOME/$REPO"
  28. # Check if repo exists, if not clone it
  29. if [ ! -d "$REPO_PATH" ]; then
  30. echo "Repository not found at $REPO_PATH, cloning..."
  31. mkdir -p "$HOME"
  32. GIT_URL="ssh://git@207.154.220.231:10022/$OWNER/$REPO.git"
  33. git clone "$GIT_URL" "$REPO_PATH"
  34. if [ $? -ne 0 ]; then
  35. echo "Failed to clone repository"
  36. exit 1
  37. fi
  38. echo "Repository cloned successfully"
  39. else
  40. echo "Repository found at $REPO_PATH"
  41. # Pull latest changes
  42. cd "$REPO_PATH" || exit 1
  43. echo "Pulling latest changes..."
  44. git pull
  45. fi
  46. # Change to repo directory
  47. cd "$REPO_PATH" || exit 1
  48. echo "Working directory: $(pwd)"
  49. # Build the prompt for Claude
  50. if [ -n "$COMMENT_BODY" ]; then
  51. # Issue comment event
  52. PROMPT="A comment was added to issue #$ISSUE_NUMBER in $OWNER/$REPO by $PUSHER.
  53. Issue Title: $ISSUE_TITLE
  54. Original Issue:
  55. $ISSUE_BODY
  56. New Comment:
  57. $COMMENT_BODY
  58. Please review the comment and respond appropriately. This issue is assigned to you."
  59. else
  60. # Issue opened/reopened event
  61. PROMPT="Issue #$ISSUE_NUMBER was $ISSUE_ACTION in $OWNER/$REPO by $PUSHER.
  62. Issue Title: $ISSUE_TITLE
  63. Issue Description:
  64. $ISSUE_BODY
  65. This issue is assigned to you. Please review and handle it accordingly."
  66. fi
  67. echo "Calling Claude Code with the issue information..."
  68. echo "---"
  69. # Call claude with the prompt
  70. claude -p "$PROMPT"
  71. echo "---"
  72. echo "Claude Code execution completed"