Skip to content

Commit 3ceb849

Browse files
authored
Workflow
1 parent 65c0989 commit 3ceb849

1 file changed

Lines changed: 50 additions & 50 deletions

File tree

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

Lines changed: 50 additions & 50 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
4+
name: AI Code Analysis (Fixed)
55

66
on:
77
pull_request:
@@ -36,6 +36,55 @@ jobs:
3636
with:
3737
node-version: '20'
3838

39+
- name: Get Code Changes
40+
id: get-changes
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
EVENT_NAME: ${{ github.event_name }}
44+
BASE_SHA: ${{ github.event.before || '' }}
45+
HEAD_SHA: ${{ github.sha }}
46+
REPO_FULL_NAME: ${{ github.repository }}
47+
run: |
48+
echo "📋 Collecting code changes for analysis..."
49+
50+
if [ "$EVENT_NAME" = "pull_request" ]; then
51+
# For PRs, get the diff between base and head
52+
PR_BASE_SHA="${{ github.event.pull_request.base.sha }}"
53+
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"
54+
curl -H "Authorization: token $GITHUB_TOKEN" \
55+
-H "Accept: application/vnd.github.v3.diff" \
56+
"https://api.github.com/repos/$REPO_FULL_NAME/compare/$PR_BASE_SHA..$PR_HEAD_SHA" \
57+
> code_changes.diff
58+
elif [ "$EVENT_NAME" = "push" ]; then
59+
# For pushes, get the diff from the previous commit
60+
if [ -n "$BASE_SHA" ] && [ "$BASE_SHA" != "0000000000000000000000000000000000000000" ]; then
61+
curl -H "Authorization: token $GITHUB_TOKEN" \
62+
-H "Accept: application/vnd.github.v3.diff" \
63+
"https://api.github.com/repos/$REPO_FULL_NAME/compare/$BASE_SHA..$HEAD_SHA" \
64+
> code_changes.diff
65+
else
66+
echo "Initial commit - showing full content of changed files" > code_changes.diff
67+
git show --name-only $HEAD_SHA | head -10 | while read file; do
68+
if [ -f "$file" ]; then
69+
echo "=== $file ===" >> code_changes.diff
70+
head -50 "$file" >> code_changes.diff
71+
echo "" >> code_changes.diff
72+
fi
73+
done
74+
fi
75+
else
76+
echo "No code changes available for this event type" > code_changes.diff
77+
fi
78+
79+
# Check if we got changes
80+
if [ -s code_changes.diff ]; then
81+
echo "✅ Code changes collected: $(wc -l < code_changes.diff) lines"
82+
echo "changes-available=true" >> $GITHUB_OUTPUT
83+
else
84+
echo "⚠️ No code changes found"
85+
echo "changes-available=false" >> $GITHUB_OUTPUT
86+
fi
87+
3988
- name: Install Google AI SDK and Create Analysis Script
4089
run: |
4190
echo "🔧 Installing Google AI SDK..."
@@ -109,55 +158,6 @@ jobs:
109158
110159
echo "✅ Analysis script created successfully"
111160
112-
- name: Get Code Changes
113-
id: get-changes
114-
env:
115-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116-
EVENT_NAME: ${{ github.event_name }}
117-
BASE_SHA: ${{ github.event.before || '' }}
118-
HEAD_SHA: ${{ github.sha }}
119-
REPO_FULL_NAME: ${{ github.repository }}
120-
run: |
121-
echo "📋 Collecting code changes for analysis..."
122-
123-
if [ "$EVENT_NAME" = "pull_request" ]; then
124-
# For PRs, get the diff between base and head
125-
PR_BASE_SHA="${{ github.event.pull_request.base.sha }}"
126-
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"
127-
curl -H "Authorization: token $GITHUB_TOKEN" \
128-
-H "Accept: application/vnd.github.v3.diff" \
129-
"https://api.github.com/repos/$REPO_FULL_NAME/compare/$PR_BASE_SHA..$PR_HEAD_SHA" \
130-
> code_changes.diff
131-
elif [ "$EVENT_NAME" = "push" ]; then
132-
# For pushes, get the diff from the previous commit
133-
if [ -n "$BASE_SHA" ] && [ "$BASE_SHA" != "0000000000000000000000000000000000000000" ]; then
134-
curl -H "Authorization: token $GITHUB_TOKEN" \
135-
-H "Accept: application/vnd.github.v3.diff" \
136-
"https://api.github.com/repos/$REPO_FULL_NAME/compare/$BASE_SHA..$HEAD_SHA" \
137-
> code_changes.diff
138-
else
139-
echo "Initial commit - showing full content of changed files" > code_changes.diff
140-
git show --name-only $HEAD_SHA | head -10 | while read file; do
141-
if [ -f "$file" ]; then
142-
echo "=== $file ===" >> code_changes.diff
143-
head -50 "$file" >> code_changes.diff
144-
echo "" >> code_changes.diff
145-
fi
146-
done
147-
fi
148-
else
149-
echo "No code changes available for this event type" > code_changes.diff
150-
fi
151-
152-
# Check if we got changes
153-
if [ -s code_changes.diff ]; then
154-
echo "✅ Code changes collected: $(wc -l < code_changes.diff) lines"
155-
echo "changes-available=true" >> $GITHUB_OUTPUT
156-
else
157-
echo "⚠️ No code changes found"
158-
echo "changes-available=false" >> $GITHUB_OUTPUT
159-
fi
160-
161161
- name: Create Analysis Prompt
162162
env:
163163
PR_TITLE: ${{ github.event.pull_request.title || format('Push Analysis - {0}', github.ref_name) }}

0 commit comments

Comments
 (0)