|
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 |
| 4 | +name: AI Code Analysis (Fixed) |
5 | 5 |
|
6 | 6 | on: |
7 | 7 | pull_request: |
|
36 | 36 | with: |
37 | 37 | node-version: '20' |
38 | 38 |
|
| 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 | +
|
39 | 88 | - name: Install Google AI SDK and Create Analysis Script |
40 | 89 | run: | |
41 | 90 | echo "🔧 Installing Google AI SDK..." |
@@ -109,55 +158,6 @@ jobs: |
109 | 158 | |
110 | 159 | echo "✅ Analysis script created successfully" |
111 | 160 |
|
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 | | -
|
161 | 161 | - name: Create Analysis Prompt |
162 | 162 | env: |
163 | 163 | PR_TITLE: ${{ github.event.pull_request.title || format('Push Analysis - {0}', github.ref_name) }} |
|
0 commit comments