handle-issue.sh 2.0 KB

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