|
1 | 1 | # Gemini AI-Powered Code Analysis |
2 | 2 | # Analyzes code changes in PRs, pushes, and branches - FOCUSES ON CODE CHANGES |
3 | 3 |
|
4 | | -name: AI Code Analysis (Fixed) |
| 4 | +name: AI Code Analysis |
5 | 5 |
|
6 | 6 | on: |
7 | 7 | pull_request: |
@@ -46,24 +46,48 @@ jobs: |
46 | 46 | REPO_FULL_NAME: ${{ github.repository }} |
47 | 47 | run: | |
48 | 48 | echo "📋 Collecting code changes for analysis..." |
| 49 | + echo "🔍 Debug info: BASE_SHA=$BASE_SHA, HEAD_SHA=$HEAD_SHA" |
49 | 50 | |
50 | 51 | if [ "$EVENT_NAME" = "pull_request" ]; then |
51 | 52 | # For PRs, get the diff between base and head |
52 | 53 | PR_BASE_SHA="${{ github.event.pull_request.base.sha }}" |
53 | 54 | PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}" |
54 | | - curl -H "Authorization: token $GITHUB_TOKEN" \ |
| 55 | + echo "🔍 PR Debug: BASE=$PR_BASE_SHA, HEAD=$PR_HEAD_SHA" |
| 56 | + |
| 57 | + curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
55 | 58 | -H "Accept: application/vnd.github.v3.diff" \ |
56 | 59 | "https://api.github.com/repos/$REPO_FULL_NAME/compare/$PR_BASE_SHA..$PR_HEAD_SHA" \ |
57 | 60 | > code_changes.diff |
| 61 | + |
| 62 | + if [ $? -ne 0 ] || [ ! -s code_changes.diff ]; then |
| 63 | + echo "⚠️ API diff failed, using git diff..." |
| 64 | + git diff $PR_BASE_SHA..$PR_HEAD_SHA > code_changes.diff |
| 65 | + fi |
| 66 | + |
58 | 67 | elif [ "$EVENT_NAME" = "push" ]; then |
59 | 68 | # For pushes, get the diff from the previous commit |
60 | 69 | if [ -n "$BASE_SHA" ] && [ "$BASE_SHA" != "0000000000000000000000000000000000000000" ]; then |
61 | | - curl -H "Authorization: token $GITHUB_TOKEN" \ |
| 70 | + echo "🔍 Push Debug: Comparing $BASE_SHA to $HEAD_SHA" |
| 71 | + |
| 72 | + # Try API first |
| 73 | + curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
62 | 74 | -H "Accept: application/vnd.github.v3.diff" \ |
63 | 75 | "https://api.github.com/repos/$REPO_FULL_NAME/compare/$BASE_SHA..$HEAD_SHA" \ |
64 | 76 | > code_changes.diff |
| 77 | + |
| 78 | + # Check if API call was successful |
| 79 | + if [ $? -ne 0 ] || [ ! -s code_changes.diff ]; then |
| 80 | + echo "⚠️ API diff failed, using git diff..." |
| 81 | + git diff $BASE_SHA..$HEAD_SHA > code_changes.diff |
| 82 | + fi |
| 83 | + |
| 84 | + # If still no diff, try git show for recent changes |
| 85 | + if [ ! -s code_changes.diff ]; then |
| 86 | + echo "⚠️ No diff available, showing recent commit changes..." |
| 87 | + git show $HEAD_SHA > code_changes.diff |
| 88 | + fi |
65 | 89 | else |
66 | | - echo "Initial commit - showing full content of changed files" > code_changes.diff |
| 90 | + echo "📄 Initial commit or no previous commit - showing current files..." |
67 | 91 | git show --name-only $HEAD_SHA | head -10 | while read file; do |
68 | 92 | if [ -f "$file" ]; then |
69 | 93 | echo "=== $file ===" >> code_changes.diff |
|
75 | 99 | else |
76 | 100 | echo "No code changes available for this event type" > code_changes.diff |
77 | 101 | fi |
| 102 | + echo "" >> code_changes.diff |
| 103 | + fi |
| 104 | + done |
| 105 | + fi |
| 106 | + else |
| 107 | + echo "No code changes available for this event type" > code_changes.diff |
| 108 | + fi |
78 | 109 | |
79 | 110 | # Check if we got changes |
80 | 111 | if [ -s code_changes.diff ]; then |
|
0 commit comments