@@ -116,30 +116,74 @@ jobs:
116116
117117 - name : Scan Codebase for Context
118118 id : scan-code
119+ env :
120+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
121+ REPO_FULL_NAME : ${{ github.repository }}
119122 run : |
120123 echo "📋 Scanning codebase for relevant context..."
121124
122- # Get recent commits for context
123- echo "📜 Recent commits:" > codebase_context.txt
124- git log --oneline -5 >> codebase_context.txt
125- echo "" >> codebase_context.txt
125+ # Get recent commits for context with git as primary method
126+ echo "📜 Collecting recent commits..."
127+ if git log --oneline -5 > recent_commits.txt 2>git_error.log; then
128+ echo "✅ Recent commits collected via git"
129+ else
130+ echo "⚠️ Failed to get recent commits via git:"
131+ cat git_error.log 2>/dev/null || echo "No git error details"
132+ echo "No recent commits available" > recent_commits.txt
133+ fi
134+
135+ # Get main plugin files for context using reliable file system operations
136+ echo "📁 Collecting plugin file structure..."
137+ echo "🔍 Main plugin files:" > codebase_context.txt
126138
127- # Get main plugin files for context
128- echo "📁 Main plugin files:" >> codebase_context.txt
129- find . -name "*.php" -path "./.*" -prune -o -name "*.php" -print | head -10 | while read file; do
130- if [ -f "$file" ]; then
131- echo "=== $file ===" >> codebase_context.txt
132- head -30 "$file" >> codebase_context.txt
133- echo "" >> codebase_context.txt
139+ # Use git ls-files as primary method (more reliable than find)
140+ echo "🔧 Using git ls-files (primary method)..."
141+ if git ls-files "*.php" | head -10 > found_files.txt 2>git_error.log; then
142+ echo "✅ Git ls-files successful"
143+ while read file; do
144+ if [ -f "$file" ] && [ -n "$file" ]; then
145+ echo "=== $file ===" >> codebase_context.txt
146+ echo "🔍 Processing: $file"
147+ if head -30 "$file" >> codebase_context.txt 2>/dev/null; then
148+ echo "✅ Added content from $file"
149+ else
150+ echo "⚠️ Failed to read $file"
151+ fi
152+ echo "" >> codebase_context.txt
153+ fi
154+ done < found_files.txt
155+ else
156+ echo "⚠️ Git ls-files failed, using find as fallback..."
157+ cat git_error.log 2>/dev/null || echo "No git error details"
158+
159+ # Find as fallback method
160+ if find . -name "*.php" -path "./.*" -prune -o -name "*.php" -print 2>/dev/null | head -10 > found_files.txt; then
161+ echo "✅ Find fallback successful"
162+ while read file; do
163+ if [ -f "$file" ] && [ -n "$file" ]; then
164+ echo "=== $file ===" >> codebase_context.txt
165+ head -30 "$file" >> codebase_context.txt 2>/dev/null
166+ echo "" >> codebase_context.txt
167+ fi
168+ done < found_files.txt
169+ else
170+ echo "❌ Both git and find methods failed"
171+ echo "No PHP files found" >> codebase_context.txt
134172 fi
135- done
173+ fi
174+
175+ # Add recent commits to context
176+ echo "" >> codebase_context.txt
177+ echo "📜 Recent Git History:" >> codebase_context.txt
178+ cat recent_commits.txt >> codebase_context.txt
136179
137- # Check if we collected context
138- if [ -s codebase_context.txt ]; then
180+ # Check if we collected context with better validation
181+ if [ -s codebase_context.txt ] && [ $(wc -l < codebase_context.txt) -gt 5 ] ; then
139182 echo "✅ Codebase context collected: $(wc -l < codebase_context.txt) lines"
140183 echo "context-available=true" >> $GITHUB_OUTPUT
141184 else
142- echo "⚠️ No codebase context found"
185+ echo "❌ Insufficient codebase context collected"
186+ echo "🔍 Context file size: $(wc -l < codebase_context.txt 2>/dev/null || echo '0') lines"
143187 echo "context-available=false" >> $GITHUB_OUTPUT
144188 fi
145189
@@ -224,6 +268,7 @@ jobs:
224268
225269 echo "🤖 Starting AI issue analysis with official Google SDK..."
226270 echo "📝 Prompt file size: $(wc -c < analysis_prompt.txt) bytes"
271+ echo "🔑 API key status: $([ -n "$GEMINI_API_KEY" ] && echo "✅ Set" || echo "❌ Missing")"
227272
228273 if node gemini-analyze.js; then
229274 echo "analysis-success=true" >> $GITHUB_OUTPUT
@@ -233,18 +278,24 @@ jobs:
233278 echo "❌ AI analysis failed - check logs for details"
234279 fi
235280
236- # Format the response
281+ # Format the response with enhanced error handling
237282 echo "## 🤖 Gemini Issue Analysis" > formatted_response.txt
238283 echo "" >> formatted_response.txt
284+
239285 if [ -s gemini_response.txt ]; then
286+ echo "📄 Adding analysis results ($(wc -c < gemini_response.txt) characters)"
240287 cat gemini_response.txt >> formatted_response.txt
241288 else
242- echo "Analysis completed but no specific recommendations at this time." >> formatted_response.txt
289+ echo "⚠️ No analysis results found - adding fallback message"
290+ echo "Analysis completed but encountered issues. Please review the issue manually and check the repository for related functionality." >> formatted_response.txt
243291 fi
244292
245293 echo "" >> formatted_response.txt
246294 echo "---" >> formatted_response.txt
247295 echo "*Analysis performed by Gemini AI on $(date)*" >> formatted_response.txt
296+
297+ # Debug: Show final response size
298+ echo "📊 Final response size: $(wc -c < formatted_response.txt) characters"
248299
249300 - name : Comment on Issue
250301 uses : actions/github-script@v8
0 commit comments