Skip to content

Commit 41ce342

Browse files
authored
Workflow
1 parent 3ceb849 commit 41ce342

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

.github/workflows/gemini-code-assistant.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Gemini AI-Powered Code Analysis
22
# Analyzes code changes in PRs, pushes, and branches - FOCUSES ON CODE CHANGES
33

4-
name: AI Code Analysis (Fixed)
4+
name: AI Code Analysis
55

66
on:
77
pull_request:
@@ -46,24 +46,48 @@ jobs:
4646
REPO_FULL_NAME: ${{ github.repository }}
4747
run: |
4848
echo "📋 Collecting code changes for analysis..."
49+
echo "🔍 Debug info: BASE_SHA=$BASE_SHA, HEAD_SHA=$HEAD_SHA"
4950
5051
if [ "$EVENT_NAME" = "pull_request" ]; then
5152
# For PRs, get the diff between base and head
5253
PR_BASE_SHA="${{ github.event.pull_request.base.sha }}"
5354
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" \
5558
-H "Accept: application/vnd.github.v3.diff" \
5659
"https://api.github.com/repos/$REPO_FULL_NAME/compare/$PR_BASE_SHA..$PR_HEAD_SHA" \
5760
> 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+
5867
elif [ "$EVENT_NAME" = "push" ]; then
5968
# For pushes, get the diff from the previous commit
6069
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" \
6274
-H "Accept: application/vnd.github.v3.diff" \
6375
"https://api.github.com/repos/$REPO_FULL_NAME/compare/$BASE_SHA..$HEAD_SHA" \
6476
> 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
6589
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..."
6791
git show --name-only $HEAD_SHA | head -10 | while read file; do
6892
if [ -f "$file" ]; then
6993
echo "=== $file ===" >> code_changes.diff
@@ -75,6 +99,13 @@ jobs:
7599
else
76100
echo "No code changes available for this event type" > code_changes.diff
77101
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
78109
79110
# Check if we got changes
80111
if [ -s code_changes.diff ]; then

0 commit comments

Comments
 (0)