@@ -109,10 +109,60 @@ jobs:
109109
110110 echo "✅ Analysis script created successfully"
111111
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+
112161 - name : Create Analysis Prompt
113162 env :
114163 PR_TITLE : ${{ github.event.pull_request.title || format('Push Analysis - {0}', github.ref_name) }}
115164 PR_AUTHOR : ${{ github.event.pull_request.user.login || github.actor }}
165+ CHANGES_AVAILABLE : ${{ steps.get-changes.outputs.changes-available }}
116166 run : |
117167 echo "📝 Creating analysis prompt..."
118168 echo "You are an expert WordPress plugin developer and security consultant." > analysis_prompt.txt
@@ -129,6 +179,16 @@ jobs:
129179 echo "4. Best practice recommendations" >> analysis_prompt.txt
130180 echo "" >> analysis_prompt.txt
131181 echo "Provide specific, actionable feedback." >> analysis_prompt.txt
182+ echo "" >> analysis_prompt.txt
183+
184+ # Add the actual code changes
185+ if [ "$CHANGES_AVAILABLE" = "true" ]; then
186+ echo "Here are the code changes to analyze:" >> analysis_prompt.txt
187+ echo "" >> analysis_prompt.txt
188+ cat code_changes.diff >> analysis_prompt.txt
189+ else
190+ echo "No code changes were detected in this commit." >> analysis_prompt.txt
191+ fi
132192
133193 - name : Run AI Analysis
134194 id : ai-analysis
0 commit comments