Skip to content

Commit ef8a559

Browse files
committed
Fix issue-fix mode script with better error handling and repo format
1 parent 627d016 commit ef8a559

2 files changed

Lines changed: 48 additions & 6 deletions

File tree

.github/workflows/claude-issue-fix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
mode: 'issue-fix'
3535
issue-number: ${{ github.event.issue.number }}
3636
repo-owner: ${{ github.repository_owner }}
37-
repo-name: ${{ github.repository }}
37+
repo-name: ${{ github.event.repository.name }}
3838
branch-prefix: 'fix'
3939
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
4040
github-token: ${{ secrets.GITHUB_TOKEN }}

scripts/issue-fix-mode.sh

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@ BRANCH_PREFIX=$4
99
ANTHROPIC_API_KEY=$5
1010
GITHUB_TOKEN=$6
1111

12+
# Validate required inputs
13+
if [ -z "$ISSUE_NUMBER" ]; then
14+
echo "Error: Missing issue number"
15+
exit 1
16+
fi
17+
18+
if [ -z "$REPO_OWNER" ]; then
19+
echo "Error: Missing repository owner"
20+
exit 1
21+
fi
22+
23+
if [ -z "$REPO_NAME" ]; then
24+
echo "Error: Missing repository name"
25+
exit 1
26+
fi
27+
28+
if [ -z "$ANTHROPIC_API_KEY" ]; then
29+
echo "Error: Missing Anthropic API key"
30+
exit 1
31+
fi
32+
33+
if [ -z "$GITHUB_TOKEN" ]; then
34+
echo "Error: Missing GitHub token"
35+
exit 1
36+
fi
37+
38+
# Log parameter values for debugging (excluding sensitive info)
39+
echo "Running issue-fix-mode with parameters:"
40+
echo "Issue Number: $ISSUE_NUMBER"
41+
echo "Repo Owner: $REPO_OWNER"
42+
echo "Repo Name: $REPO_NAME"
43+
echo "Branch Prefix: ${BRANCH_PREFIX:-fix}"
44+
1245
# Set up authentication
1346
echo "$GITHUB_TOKEN" | gh auth login --with-token
1447
export ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY"
@@ -23,14 +56,18 @@ FIX_BRANCH="${BRANCH_PREFIX:-fix}-issue-${ISSUE_NUMBER}-${DATE}"
2356

2457
# Get issue details
2558
echo "Fetching issue #$ISSUE_NUMBER details"
26-
ISSUE_DETAILS=$(gh issue view $ISSUE_NUMBER --json title,body,labels)
59+
# Make sure we're using the correct repo format for the gh cli
60+
FULL_REPO="$REPO_OWNER/$REPO_NAME"
61+
echo "Using repository: $FULL_REPO"
62+
ISSUE_DETAILS=$(gh issue view $ISSUE_NUMBER --repo "$FULL_REPO" --json title,body,labels)
2763

2864
ISSUE_TITLE=$(echo "$ISSUE_DETAILS" | jq -r '.title')
2965
ISSUE_BODY=$(echo "$ISSUE_DETAILS" | jq -r '.body')
3066
ISSUE_LABELS=$(echo "$ISSUE_DETAILS" | jq -r '.labels[].name' | tr '\n' ',' | sed 's/,$//')
3167

3268
# Get repo information
33-
REPO_INFO=$(gh repo view --json name,description,defaultBranchRef,languages)
69+
echo "Fetching repository information"
70+
REPO_INFO=$(gh repo view "$FULL_REPO" --json name,description,defaultBranchRef,languages)
3471
REPO_DESC=$(echo "$REPO_INFO" | jq -r '.description')
3572
DEFAULT_BRANCH=$(echo "$REPO_INFO" | jq -r '.defaultBranchRef.name')
3673
REPO_LANGUAGES=$(echo "$REPO_INFO" | jq -r '.languages[].name' | tr '\n' ', ' | sed 's/,$//')
@@ -74,7 +111,10 @@ EOF
74111

75112
# Run Claude CLI to analyze the issue
76113
echo "Sending request to Claude for issue analysis..."
77-
echo "$ANALYZE_PROMPT" | claude -p - > "$RESPONSE_FILE"
114+
if ! echo "$ANALYZE_PROMPT" | claude -p - > "$RESPONSE_FILE"; then
115+
echo "Error: Claude API request failed. Check your API key and connectivity."
116+
exit 1
117+
fi
78118

79119
# Parse Claude's response to extract files to examine
80120
FILES_TO_EXAMINE=$(grep -Eo "Files Involved:.*" -A 20 "$RESPONSE_FILE" | grep -v "Proposed Changes:" | grep -v "Testing Plan:" | grep "/" | sed -E 's/^[ -]*([^ ].*)/\1/' | sed -E 's/ *$//' | grep -v "^$")
@@ -225,7 +265,8 @@ EOF
225265
)
226266
227267
# Create the PR
228-
PR_URL=$(gh pr create --title "Fix: $ISSUE_TITLE" --body "$PR_BODY" --base "$DEFAULT_BRANCH" --head "$FIX_BRANCH")
268+
echo "Creating pull request"
269+
PR_URL=$(gh pr create --repo "$FULL_REPO" --title "Fix: $ISSUE_TITLE" --body "$PR_BODY" --base "$DEFAULT_BRANCH" --head "$FIX_BRANCH")
229270
230271
# Add a comment to the issue
231272
ISSUE_COMMENT=$(cat <<EOF
@@ -244,7 +285,8 @@ Please review the PR and test the changes to verify they resolve the issue.
244285
EOF
245286
)
246287
247-
gh issue comment $ISSUE_NUMBER --body "$ISSUE_COMMENT"
288+
echo "Adding comment to issue #$ISSUE_NUMBER"
289+
gh issue comment "$ISSUE_NUMBER" --repo "$FULL_REPO" --body "$ISSUE_COMMENT"
248290
249291
# Clean up temp files
250292
rm -f "$RESPONSE_FILE" "$FIX_DETAILS_FILE"

0 commit comments

Comments
 (0)